summaryrefslogtreecommitdiffstats
path: root/kandy/src/main.cpp
blob: 982a1a7f22f4b94b2cfa9f9c46ace2bf882c6cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
    This file is part of Kandy.

    Copyright (c) 2001 Cornelius Schumacher <[email protected]>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#include <tqfile.h>

#include <kapplication.h>
#include <dcopclient.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>

#include "modem.h"
#include "kandy.h"
#include "mobilemain.h"
#include "mobilegui.h"
#include "commandscheduler.h"
#include "kandyprefs.h"

static const char description[] =
    I18N_NOOP("Communicating with your mobile phone.");

static const char version[] = "0.5.1";

static KCmdLineOptions options[] =
{
   { "terminal", I18N_NOOP("Show terminal window"), 0 },
   { "mobilegui", I18N_NOOP("Show mobile GUI"), 0 },
   { "nogui", I18N_NOOP("Do not show GUI"), 0 },
   { "+[profile]", I18N_NOOP("Filename of command profile file"), 0 },
   KCmdLineLastOption // End of options.
};

void initModem(Modem *modem)
{
  kdDebug() << "Opening serial Device: "
            << KandyPrefs::serialDevice()
            << endl;

  modem->setSpeed( KandyPrefs::baudRate().toUInt() );
  modem->setData(8);
  modem->setParity('N');
  modem->setStop(1);

#if 0
  if (!modem->dsrOn()) {
    KMessageBox::sorry(this, i18n("Modem is off."), i18n("Modem Error"));
    modem->close();
    return;
  }
  if (!modem->ctsOn()) {
    KMessageBox::sorry(this, i18n("Modem is busy."), i18n("Modem Error"));
    modem->close();
    return;
  }
#endif

#if 0
  modem->writeLine("");
  usleep(250000);
  modem->flush();
  modem->writeLine("ATZ");
#endif
}

int main(int argc, char **argv)
{
  KAboutData about("kandy", I18N_NOOP("Kandy"), version, description,
                   KAboutData::License_GPL, "(C) 2001 Cornelius Schumacher",0,
                   "http://kandy.kde.org/");
  about.addAuthor( "Cornelius Schumacher", 0, "[email protected]" );
  about.addAuthor( "Heiko Falk", 0, "[email protected]" );
  KCmdLineArgs::init(argc,argv,&about);
  KCmdLineArgs::addCmdLineOptions(options);

  KApplication app;
  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

  // register ourselves as a dcop client
  app.dcopClient()->registerAs(app.name(),false);

  Modem *modem = new Modem(KandyPrefs::self());
  CommandScheduler *scheduler = new CommandScheduler(modem);

  // see if we are starting with session management
  if (app.isRestored()) {
    // TODO: do session management
//      RESTORE(Kandy)
  } else
  {
    // no session.. just start up normally
    Kandy *k = new Kandy(scheduler);

    MobileMain *m = new MobileMain(scheduler, KandyPrefs::self());
    
    if (!args->isSet("gui")) {
    } else {
      if (KandyPrefs::startupTerminalWin() ||
          args->isSet("terminal")) {
        k->show();
      }
      if (KandyPrefs::startupMobileWin() ||
          args->isSet("mobilegui")) {
        m->show();
      }
    }

    if (args->count() == 1) {
      k->load(TQFile::decodeName(args->arg(0)));
    } else if (args->count() > 1) {
      args->usage();
    }

    args->clear();

    TQObject::connect(k,TQT_SIGNAL(showMobileWin()),m,TQT_SLOT(show()));
    TQObject::connect(m,TQT_SIGNAL(showTerminalWin()),k,TQT_SLOT(show()));
    TQObject::connect(m,TQT_SIGNAL(showPreferencesWin()),
                     k,TQT_SLOT(optionsPreferences()));

    TQObject::connect( m->view(), TQT_SIGNAL( connectModem() ), k,
                      TQT_SLOT( modemConnect() ) );
    TQObject::connect( m->view(), TQT_SIGNAL( disconnectModem() ), k,
                      TQT_SLOT( modemDisconnect() ) );

    TQObject::connect( modem, TQT_SIGNAL( errorMessage( const TQString & ) ),
                      k, TQT_SLOT( showErrorMessage( const TQString & ) ) );

    initModem( modem );

    if ( KandyPrefs::startupModem() )
      m->view()->toggleConnection();
  }

  return app.exec();
}