kandy Library API Documentation

main.cpp

00001 #include <qfile.h>
00002 
00003 #include <kapplication.h>
00004 #include <dcopclient.h>
00005 #include <kaboutdata.h>
00006 #include <kcmdlineargs.h>
00007 #include <klocale.h>
00008 #include <kdebug.h>
00009 #include <kmessagebox.h>
00010 
00011 #include "modem.h"
00012 #include "kandy.h"
00013 #include "mobilemain.h"
00014 #include "commandscheduler.h"
00015 #include "kandyprefs.h"
00016 
00017 static const char *description =
00018     I18N_NOOP("Communicating with your mobile phone.");
00019 
00020 static const char *version = "0.3";
00021 
00022 static KCmdLineOptions options[] = 
00023 {
00024    { "terminal", I18N_NOOP("Show terminal window."), 0 },
00025    { "mobilegui", I18N_NOOP("Show mobile GUI."), 0 },
00026    { "nogui", I18N_NOOP("Don't show GUI."), 0 },
00027    { "+[profile]", I18N_NOOP("Filename of command profile file."), 0 },
00028    { 0, 0, 0 } // End of options.
00029 };
00030 
00031 void initModem(Modem *modem)
00032 {
00033   kdDebug() << "Opening serial Device: "
00034             << KandyPrefs::instance()->mSerialDevice
00035             << endl;
00036 
00037   modem->setDevice(KandyPrefs::instance()->mSerialDevice);
00038   modem->setSpeed(19200);
00039   modem->setData(8);
00040   modem->setParity('N');
00041   modem->setStop(1);
00042 
00043 #if 0
00044   if (!modem->dsrOn()) {
00045     KMessageBox::sorry(this, i18n("Modem is off."), i18n("Modem Error"));
00046     modem->close();
00047     return;
00048   }
00049   if (!modem->ctsOn()) {
00050     KMessageBox::sorry(this, i18n("Modem is busy."), i18n("Modem Error"));
00051     modem->close();
00052     return;
00053   }
00054 #endif
00055 
00056 #if 0
00057   modem->writeLine("");
00058   usleep(250000);
00059   modem->flush();
00060   modem->writeLine("ATZ");
00061 #endif
00062 }
00063 
00064 int main(int argc, char **argv)
00065 {
00066   KAboutData about("kandy", I18N_NOOP("Kandy"), version, description,
00067                    KAboutData::License_GPL, "(C) 2001 Cornelius Schumacher",0,
00068                    "http://devel-home.kde.org/~kandy");
00069   about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00070   KCmdLineArgs::init(argc,argv,&about);
00071   KCmdLineArgs::addCmdLineOptions(options);
00072 
00073   KApplication app;
00074   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00075 
00076   // register ourselves as a dcop client
00077   app.dcopClient()->registerAs(app.name(),false);
00078 
00079   Modem *modem = new Modem;
00080   initModem(modem);
00081   CommandScheduler *scheduler = new CommandScheduler(modem);
00082   
00083   // see if we are starting with session management
00084   if (app.isRestored()) {
00085     // TODO: do session management
00086 //      RESTORE(Kandy)
00087   } else
00088   {
00089     // no session.. just start up normally
00090     Kandy *k = new Kandy(scheduler);
00091     
00092     MobileMain *m = new MobileMain(scheduler);
00093     if (!args->isSet("gui")) {
00094     } else {
00095       if (KandyPrefs::instance()->mStartupTerminalWin ||
00096           args->isSet("terminal")) {
00097         k->show();
00098       }
00099       if (KandyPrefs::instance()->mStartupMobileWin ||
00100           args->isSet("mobilegui")) {
00101         m->show();
00102       }
00103     }
00104     
00105     if (args->count() == 1) {
00106       k->load(QFile::decodeName(args->arg(0)));
00107     } else if (args->count() > 1) {
00108       args->usage();
00109     }
00110  
00111     args->clear();
00112  
00113     QObject::connect(k,SIGNAL(showMobileWin()),m,SLOT(show()));
00114     QObject::connect(m,SIGNAL(showTerminalWin()),k,SLOT(show()));
00115     QObject::connect(m,SIGNAL(showPreferencesWin()),
00116                      k,SLOT(optionsPreferences()));
00117     QObject::connect(m,SIGNAL(modemConnect()),k,SLOT(modemConnect()));
00118     QObject::connect(m,SIGNAL(modemDisconnect()),k,SLOT(modemDisconnect()));
00119     QObject::connect(k,SIGNAL(connectStateChanged(bool)),
00120                      m,SLOT(setConnected(bool)));
00121 
00122     if (KandyPrefs::instance()->mStartupModem) k->modemConnect();
00123   }
00124 
00125   return app.exec();
00126 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:32 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001