summaryrefslogtreecommitdiffabout
path: root/kaddressbook/mainembedded.cpp
blob: 3f6f69d741cce321f980921f09ed8fc3b5ccc507 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#ifndef DESKTOP_VERSION
#include <qpe/qpeapplication.h>
#include <qpe/global.h>
#include <stdlib.h>
#else
#include <qapplication.h>
#include <qwindowsstyle.h> 
#include <qplatinumstyle.h> 
#include <qmainwindow.h> 
#endif

#include <kstandarddirs.h>
#include <kglobal.h>
#include <stdio.h>
#include <qdir.h>
#include "kaddressbookmain.h"

int main( int argc, char **argv )
{
#ifndef DESKTOP_VERSION
  QPEApplication a( argc, argv );
  a.setKeepRunning ();
#else
  QApplication a( argc, argv ); 
  QApplication::setStyle( new QPlatinumStyle ());
#endif
  
  bool exitHelp = false;
  if ( argc > 1 ) {
      QString command = argv[1];
      if (  command == "-help" ){
          printf("KA/E command line commands:\n");
          printf("  no command: Start KA/E in usual way\n");
          printf("  -help: This output\n");  
          printf(" KA/E is exiting now. Bye!\n");
          exitHelp = true;
      }
  }
  if ( ! exitHelp ) {

    KGlobal::setAppName( "kaddressbook" );
#ifndef DESKTOP_VERSION
      KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) );  
      KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/");
#else
      QString fileName ;
#ifndef _WIN32_
    fileName  = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons16/";
#else
    fileName   = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\icons16\\";
#endif
    KGlobal::iconLoader()->setIconPath(fileName);
    QString appdir = QDir::homeDirPath();
    if ( appdir.right(1) == "\\" ||   appdir.right(1) == "/" )
        appdir += "kaddressbook";
    else
        appdir += "/kaddressbook";
    KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
    //     qDebug(" %s  ",KStandardDirs::appDir().latin1() );
#endif // desktop
       QDir app_dir;
       if ( !app_dir.exists(KStandardDirs::appDir()) )
           app_dir.mkdir (KStandardDirs::appDir());

       KAddressBookMain* m = new KAddressBookMain();
//US      MainWindow m;
//US      QObject::connect( &a, SIGNAL (appMessage ( const QCString &, const QByteArray & )),&m, SLOT(recieve(  const QCString&, const QByteArray& )));

#ifndef DESKTOP_VERSION
       a.showMainWidget(m );
       m->showMaximized();
        
#else
      a.setMainWidget(m );
      m->show();
      //m->resize( 640, 480 );
#endif
      a.exec();
      
  }
  qDebug("KA: Bye! ");
}

/*
#include <stdlib.h>

#include <qstring.h>

#include <kabc/stdaddressbook.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <kcrash.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstartupinfo.h>
#include <kuniqueapplication.h>
#include <kwin.h>

#include "kaddressbookmain.h"
#include "kabcore.h"

extern "C" {

void crashHandler( int )
{
  KABC::StdAddressBook::handleCrash();
  ::exit( 0 );
}

}

class KAddressBookApp : public KUniqueApplication {
  public:
    KAddressBookApp() : mMainWin( 0 ) {}
    ~KAddressBookApp() {}

    int newInstance();

  private:
    KAddressBookMain *mMainWin;
};

int KAddressBookApp::newInstance()
{
  if ( isRestored() ) {
    // There can only be one main window
    if ( KMainWindow::canBeRestored( 1 ) ) {
      mMainWin = new KAddressBookMain;
      mMainWin->show();
      mMainWin->restore( 1 );
    }
  } else {
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

    QCString addrStr = args->getOption( "addr" );
    QCString uidStr = args->getOption( "uid" );
    QString addr;
    QString uid;
    if ( !addrStr.isEmpty() )
      addr = QString::fromLocal8Bit( addrStr );
    if ( !uidStr.isEmpty() )
      uid = QString::fromLocal8Bit( uidStr );


    if ( args->isSet( "editor-only" ) ) {
      if ( !mMainWin )
        mMainWin = new KAddressBookMain;
        KStartupInfo::appStarted();
        mMainWin->hide();
    } else {
      if ( mMainWin ) {
        mMainWin->show();
        KWin::setActiveWindow( mMainWin->winId() );
      } else {
        mMainWin = new KAddressBookMain;
        mMainWin->show();
      }
    }
    // Can not see why anyone would pass both a uid and an email address, so I'll leave it that two contact editors will show if they do
    if ( !addr.isEmpty() )
      mMainWin->addEmail( addr );

    if ( !uid.isEmpty() )
      mMainWin->showContactEditor( uid );
    if ( args->isSet( "new-contact" ) ) {
      mMainWin->newContact();
    }
  }

  KCrash::setEmergencySaveFunction( crashHandler );

  return 0;
}

// the dummy argument is required, because KMail apparently sends an empty
// argument.
static KCmdLineOptions kmoptions[] =
{
  { "a", 0 , 0 },
  { "addr <email>", I18N_NOOP( "Shows contact editor with given email address" ), 0 },
  { "uid <uid>", I18N_NOOP( "Shows contact editor with given uid" ), 0 },
  { "editor-only", I18N_NOOP( "Launches in editor only mode" ), 0 },
  { "new-contact", I18N_NOOP( "Launches editor for the new contact" ), 0 },
  { "+[argument]", I18N_NOOP( "dummy argument" ), 0},
  { 0, 0, 0}
};

int main( int argc, char *argv[] )
{
  KLocale::setMainCatalogue( "kaddressbook" );

  KCmdLineArgs::init( argc, argv, KABCore::createAboutData() );
  KCmdLineArgs::addCmdLineOptions( kmoptions );
  KUniqueApplication::addCmdLineOptions();

  if ( !KAddressBookApp::start() )
    exit( 0 );

  KAddressBookApp app;
  KGlobal::locale()->insertCatalogue( "libkdepim" );

  return app.exec();
}
*/