kandy

main.cpp

00001 /*
00002     This file is part of Kandy.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qfile.h>
00026 
00027 #include <kapplication.h>
00028 #include <dcopclient.h>
00029 #include <kaboutdata.h>
00030 #include <kcmdlineargs.h>
00031 #include <klocale.h>
00032 #include <kdebug.h>
00033 #include <kmessagebox.h>
00034 
00035 #include "modem.h"
00036 #include "kandy.h"
00037 #include "mobilemain.h"
00038 #include "mobilegui.h"
00039 #include "commandscheduler.h"
00040 #include "kandyprefs.h"
00041 
00042 static const char description[] =
00043     I18N_NOOP("Communicating with your mobile phone.");
00044 
00045 static const char version[] = "0.5.1";
00046 
00047 static KCmdLineOptions options[] =
00048 {
00049    { "terminal", I18N_NOOP("Show terminal window"), 0 },
00050    { "mobilegui", I18N_NOOP("Show mobile GUI"), 0 },
00051    { "nogui", I18N_NOOP("Do not show GUI"), 0 },
00052    { "+[profile]", I18N_NOOP("Filename of command profile file"), 0 },
00053    KCmdLineLastOption // End of options.
00054 };
00055 
00056 void initModem(Modem *modem)
00057 {
00058   kdDebug() << "Opening serial Device: "
00059             << KandyPrefs::serialDevice()
00060             << endl;
00061 
00062   modem->setSpeed( KandyPrefs::baudRate().toUInt() );
00063   modem->setData(8);
00064   modem->setParity('N');
00065   modem->setStop(1);
00066 
00067 #if 0
00068   if (!modem->dsrOn()) {
00069     KMessageBox::sorry(this, i18n("Modem is off."), i18n("Modem Error"));
00070     modem->close();
00071     return;
00072   }
00073   if (!modem->ctsOn()) {
00074     KMessageBox::sorry(this, i18n("Modem is busy."), i18n("Modem Error"));
00075     modem->close();
00076     return;
00077   }
00078 #endif
00079 
00080 #if 0
00081   modem->writeLine("");
00082   usleep(250000);
00083   modem->flush();
00084   modem->writeLine("ATZ");
00085 #endif
00086 }
00087 
00088 int main(int argc, char **argv)
00089 {
00090   KAboutData about("kandy", I18N_NOOP("Kandy"), version, description,
00091                    KAboutData::License_GPL, "(C) 2001 Cornelius Schumacher",0,
00092                    "http://kandy.kde.org/");
00093   about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00094   about.addAuthor( "Heiko Falk", 0, "hf2@ls12.cs.uni-dortmund.de" );
00095   KCmdLineArgs::init(argc,argv,&about);
00096   KCmdLineArgs::addCmdLineOptions(options);
00097 
00098   KApplication app;
00099   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00100 
00101   // register ourselves as a dcop client
00102   app.dcopClient()->registerAs(app.name(),false);
00103 
00104   Modem *modem = new Modem(KandyPrefs::self());
00105   CommandScheduler *scheduler = new CommandScheduler(modem);
00106 
00107   // see if we are starting with session management
00108   if (app.isRestored()) {
00109     // TODO: do session management
00110 //      RESTORE(Kandy)
00111   } else
00112   {
00113     // no session.. just start up normally
00114     Kandy *k = new Kandy(scheduler);
00115 
00116     MobileMain *m = new MobileMain(scheduler, KandyPrefs::self());
00117     
00118     if (!args->isSet("gui")) {
00119     } else {
00120       if (KandyPrefs::startupTerminalWin() ||
00121           args->isSet("terminal")) {
00122         k->show();
00123       }
00124       if (KandyPrefs::startupMobileWin() ||
00125           args->isSet("mobilegui")) {
00126         m->show();
00127       }
00128     }
00129 
00130     if (args->count() == 1) {
00131       k->load(QFile::decodeName(args->arg(0)));
00132     } else if (args->count() > 1) {
00133       args->usage();
00134     }
00135 
00136     args->clear();
00137 
00138     QObject::connect(k,SIGNAL(showMobileWin()),m,SLOT(show()));
00139     QObject::connect(m,SIGNAL(showTerminalWin()),k,SLOT(show()));
00140     QObject::connect(m,SIGNAL(showPreferencesWin()),
00141                      k,SLOT(optionsPreferences()));
00142 
00143     QObject::connect( m->view(), SIGNAL( connectModem() ), k,
00144                       SLOT( modemConnect() ) );
00145     QObject::connect( m->view(), SIGNAL( disconnectModem() ), k,
00146                       SLOT( modemDisconnect() ) );
00147 
00148     QObject::connect( modem, SIGNAL( errorMessage( const QString & ) ),
00149                       k, SLOT( showErrorMessage( const QString & ) ) );
00150 
00151     initModem( modem );
00152 
00153     if ( KandyPrefs::startupModem() )
00154       m->view()->toggleConnection();
00155   }
00156 
00157   return app.exec();
00158 }
KDE Home | KDE Accessibility Home | Description of Access Keys