kandy

main.cpp
1/*
2 This file is part of Kandy.
3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tqfile.h>
26
27#include <tdeapplication.h>
28#include <dcopclient.h>
29#include <tdeaboutdata.h>
30#include <tdecmdlineargs.h>
31#include <tdelocale.h>
32#include <kdebug.h>
33#include <tdemessagebox.h>
34
35#include "modem.h"
36#include "kandy.h"
37#include "mobilemain.h"
38#include "mobilegui.h"
39#include "commandscheduler.h"
40#include "kandyprefs.h"
41
42static const char description[] =
43 I18N_NOOP("Communicating with your mobile phone.");
44
45static const char version[] = "0.5.1";
46
47static TDECmdLineOptions options[] =
48{
49 { "terminal", I18N_NOOP("Show terminal window"), 0 },
50 { "mobilegui", I18N_NOOP("Show mobile GUI"), 0 },
51 { "nogui", I18N_NOOP("Do not show GUI"), 0 },
52 { "+[profile]", I18N_NOOP("Filename of command profile file"), 0 },
53 TDECmdLineLastOption // End of options.
54};
55
56void initModem(Modem *modem)
57{
58 kdDebug() << "Opening serial Device: "
59 << KandyPrefs::serialDevice()
60 << endl;
61
62 modem->setSpeed( KandyPrefs::baudRate().toUInt() );
63 modem->setData(8);
64 modem->setParity('N');
65 modem->setStop(1);
66
67#if 0
68 if (!modem->dsrOn()) {
69 KMessageBox::sorry(this, i18n("Modem is off."), i18n("Modem Error"));
70 modem->close();
71 return;
72 }
73 if (!modem->ctsOn()) {
74 KMessageBox::sorry(this, i18n("Modem is busy."), i18n("Modem Error"));
75 modem->close();
76 return;
77 }
78#endif
79
80#if 0
81 modem->writeLine("");
82 usleep(250000);
83 modem->flush();
84 modem->writeLine("ATZ");
85#endif
86}
87
88int main(int argc, char **argv)
89{
90 TDEAboutData about("kandy", I18N_NOOP("Kandy"), version, description,
91 TDEAboutData::License_GPL, "(C) 2001 Cornelius Schumacher",0,
92 "http://kandy.kde.org/");
93 about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
94 about.addAuthor( "Heiko Falk", 0, "hf2@ls12.cs.uni-dortmund.de" );
95 TDECmdLineArgs::init(argc,argv,&about);
96 TDECmdLineArgs::addCmdLineOptions(options);
97
98 TDEApplication app;
99 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
100
101 // register ourselves as a dcop client
102 app.dcopClient()->registerAs(app.name(),false);
103
104 Modem *modem = new Modem(KandyPrefs::self());
105 CommandScheduler *scheduler = new CommandScheduler(modem);
106
107 // see if we are starting with session management
108 if (app.isRestored()) {
109 // TODO: do session management
110// RESTORE(Kandy)
111 } else
112 {
113 // no session.. just start up normally
114 Kandy *k = new Kandy(scheduler);
115
116 MobileMain *m = new MobileMain(scheduler, KandyPrefs::self());
117
118 if (!args->isSet("gui")) {
119 } else {
120 if (KandyPrefs::startupTerminalWin() ||
121 args->isSet("terminal")) {
122 k->show();
123 }
124 if (KandyPrefs::startupMobileWin() ||
125 args->isSet("mobilegui")) {
126 m->show();
127 }
128 }
129
130 if (args->count() == 1) {
131 k->load(TQFile::decodeName(args->arg(0)));
132 } else if (args->count() > 1) {
133 args->usage();
134 }
135
136 args->clear();
137
138 TQObject::connect(k,TQ_SIGNAL(showMobileWin()),m,TQ_SLOT(show()));
139 TQObject::connect(m,TQ_SIGNAL(showTerminalWin()),k,TQ_SLOT(show()));
140 TQObject::connect(m,TQ_SIGNAL(showPreferencesWin()),
141 k,TQ_SLOT(optionsPreferences()));
142
143 TQObject::connect( m->view(), TQ_SIGNAL( connectModem() ), k,
144 TQ_SLOT( modemConnect() ) );
145 TQObject::connect( m->view(), TQ_SIGNAL( disconnectModem() ), k,
146 TQ_SLOT( modemDisconnect() ) );
147
148 TQObject::connect( modem, TQ_SIGNAL( errorMessage( const TQString & ) ),
149 k, TQ_SLOT( showErrorMessage( const TQString & ) ) );
150
151 initModem( modem );
152
153 if ( KandyPrefs::startupModem() )
154 m->view()->toggleConnection();
155 }
156
157 return app.exec();
158}
This class serves as the main window for Kandy.
Definition: kandy.h:49
void load(const TQString &url)
Use this method to load whatever file/URL you have.
Definition: kandy.cpp:102
This class serves as the main window for MobileMain.
Definition: mobilemain.h:47