00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 "commandscheduler.h"
00039 #include "kandyprefs.h"
00040
00041 static const char description[] =
00042 I18N_NOOP("Communicating with your mobile phone.");
00043
00044 static const char version[] = "0.4";
00045
00046 static KCmdLineOptions options[] =
00047 {
00048 { "terminal", I18N_NOOP("Show terminal window."), 0 },
00049 { "mobilegui", I18N_NOOP("Show mobile GUI."), 0 },
00050 { "nogui", I18N_NOOP("Don't show GUI."), 0 },
00051 { "+[profile]", I18N_NOOP("Filename of command profile file."), 0 },
00052 KCmdLineLastOption
00053 };
00054
00055 void initModem(Modem *modem)
00056 {
00057 kdDebug() << "Opening serial Device: "
00058 << KandyPrefs::serialDevice()
00059 << endl;
00060
00061 modem->setDevice(KandyPrefs::serialDevice());
00062 modem->setSpeed(19200);
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://devel-home.kde.org/~kandy");
00093 about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00094 KCmdLineArgs::init(argc,argv,&about);
00095 KCmdLineArgs::addCmdLineOptions(options);
00096
00097 KApplication app;
00098 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00099
00100
00101 app.dcopClient()->registerAs(app.name(),false);
00102
00103 Modem *modem = new Modem;
00104 CommandScheduler *scheduler = new CommandScheduler(modem);
00105
00106
00107 if (app.isRestored()) {
00108
00109
00110 } else
00111 {
00112
00113 Kandy *k = new Kandy(scheduler);
00114
00115 MobileMain *m = new MobileMain(scheduler);
00116 if (!args->isSet("gui")) {
00117 } else {
00118 if (KandyPrefs::startupTerminalWin() ||
00119 args->isSet("terminal")) {
00120 k->show();
00121 }
00122 if (KandyPrefs::startupMobileWin() ||
00123 args->isSet("mobilegui")) {
00124 m->show();
00125 }
00126 }
00127
00128 if (args->count() == 1) {
00129 k->load(QFile::decodeName(args->arg(0)));
00130 } else if (args->count() > 1) {
00131 args->usage();
00132 }
00133
00134 args->clear();
00135
00136 QObject::connect(k,SIGNAL(showMobileWin()),m,SLOT(show()));
00137 QObject::connect(m,SIGNAL(showTerminalWin()),k,SLOT(show()));
00138 QObject::connect(m,SIGNAL(showPreferencesWin()),
00139 k,SLOT(optionsPreferences()));
00140 QObject::connect(m,SIGNAL(modemConnect()),k,SLOT(modemConnect()));
00141 QObject::connect(m,SIGNAL(modemDisconnect()),k,SLOT(modemDisconnect()));
00142 QObject::connect(k,SIGNAL(connectStateChanged(bool)),
00143 m,SLOT(setConnected(bool)));
00144
00145 QObject::connect( modem, SIGNAL( errorMessage( const QString & ) ),
00146 k, SLOT( showErrorMessage( const QString & ) ) );
00147
00148 initModem(modem);
00149
00150 if (KandyPrefs::startupModem()) k->modemConnect();
00151 }
00152
00153 return app.exec();
00154 }