summaryrefslogtreecommitdiffstats
path: root/quanta/src/kqapp.cpp
blob: 212bc68f1fd98900dd07a867b87dcf4c57e25c01 (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
    KQApplication.cpp

    KNode, the KDE newsreader
    Copyright (c) 1999-2001 the KNode authors.
    See file AUTHORS for details

    Rewritten for Quanta Plus: (C) 2002, 2003 Andras Mantia <amantia@kde.org>

    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.
    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, US
*/

#include <tqtimer.h>

#include <kconfig.h>
#include <kdebug.h>
#include <twin.h>
#include <kcmdlineargs.h>
#include <kurl.h>
#include <kiconloader.h>
#include <kstandarddirs.h>
#include <kglobalsettings.h>
#include <ksplashscreen.h>
#include <dcopclient.h>
#include <tdeversion.h>

#include "config.h"
#include "quantacommon.h"
#include "project.h"
#include "quanta.h"
#include "quanta_init.h"
#include "kqapp.h"

QuantaApp *quantaApp = 0L; //global pointer to the main application object
#define SPLASH_PICTURE "quantalogo"

KSplash::KSplash()
 : TQFrame( 0L, "Quanta" QUANTA_VERSION,
   TQWidget::WStyle_NoBorder | TQWidget::WStyle_Customize | WX11BypassWM)
{
   TQPixmap pm( UserIcon(SPLASH_PICTURE) );

   setBackgroundPixmap(pm);
  TQRect desk = KGlobalSettings::splashScreenDesktopGeometry();
  setGeometry( desk.center().x()-225, desk.center().y()-150, 450, 300 );
  setLineWidth(0);
  show();
}


KSplash::~KSplash()
{
}


KQApplication::KQApplication()
 : KApplication()
{
   args = KCmdLineArgs::parsedArgs();
   splash = 0L;

   KGlobal::dirs()->addPrefix(PREFIX);
   dcopClient()->registerAs("quanta", true);

//FIXME: Do not hide the problem, but really fix the session restoration.
//I have no idea how to do it, but it may be broken because of delayed
//initialization in QuantaApp
/*   if (isRestored())
   {
     RESTORE(QuantaApp);
   }
   else */
   {
     KConfig *config = kapp->config();
     config->setGroup("General Options");
     int mdiMode = config->readNumEntry("MDI mode", KMdi::IDEAlMode);
     TQString tqlayout = config->readEntry("Window tqlayout", "Default");
     if (tqlayout == "Default" || args->isSet("resettqlayout"))
     {
         mdiMode = KMdi::IDEAlMode;
         config->writeEntry("MDI mode", KMdi::IDEAlMode);
         config->writeEntry("Window tqlayout", "Default");
     }
     quantaApp = new QuantaApp(mdiMode);
     config->setGroup("General Options");
    if (config->readBoolEntry("Show Splash", true) && args->isSet("logo"))
     {
      sp = new KSplashScreen(UserIcon(SPLASH_PICTURE));
      sp->show();
      connect(quantaApp, TQT_SIGNAL(showSplash(bool)), sp, TQT_SLOT(setShown(bool)));
      TQTimer::singleShot(10*1000, this, TQT_SLOT(slotSplashTimeout()));
     }
     setMainWidget(quantaApp);
     slotInit();
   }
}

void KQApplication::slotInit()
{
  KQApplicationPrivate::init();
}

KQApplication::~KQApplication()
{
}

void KQApplication::slotSplashTimeout()
{
  delete splash;
  delete sp;
  splash = 0L;
  sp = 0L;
}

KQUniqueApplication::KQUniqueApplication()
 : KUniqueApplication()
{
  KGlobal::dirs()->addPrefix(PREFIX);
  dcopClient()->registerAs("quanta", false);
}

KQUniqueApplication::~KQUniqueApplication()
{
}


int KQUniqueApplication::newInstance()
{
  args = KCmdLineArgs::parsedArgs();
  if (mainWidget())
  {
    KWin::activateWindow( mainWidget()->winId() );
    quantaApp = static_cast<QuantaApp*>(mainWidget());
    quantaApp->setParserEnabled(false);
    for (int i = 0; i < args->count(); i++)
    {
      quantaApp->slotFileOpen(args->url(i), quantaApp->defaultEncoding());  // load initial files
    }
    quantaApp->setParserEnabled(true);
    quantaApp->reparse(true);
  }
  else
  {
    splash = 0L;
    KConfig *config = kapp->config();
    config->setGroup("General Options");
    int mdiMode = config->readNumEntry("MDI mode", KMdi::IDEAlMode);
    TQString tqlayout = config->readEntry("Window tqlayout", "Default");
    if (tqlayout == "Default" || args->isSet("resettqlayout"))
    {
        mdiMode = KMdi::IDEAlMode;
        config->writeEntry("Window tqlayout", "Default");
        config->writeEntry("MDI mode", KMdi::IDEAlMode);
    }
    quantaApp = new QuantaApp(mdiMode);
    config->setGroup("General Options");
    if (config->readBoolEntry("Show Splash", true) && args->isSet("logo"))
    {
      sp = new KSplashScreen(UserIcon(SPLASH_PICTURE));
      sp->show();
      connect(quantaApp, TQT_SIGNAL(showSplash(bool)), sp, TQT_SLOT(setShown(bool)));
      TQTimer::singleShot(10*1000, this, TQT_SLOT(slotSplashTimeout()));
    }
    setMainWidget(quantaApp);
    slotInit();
  }

  return 0;
}

void KQUniqueApplication::slotInit()
{
  KQApplicationPrivate::init();
}

void KQUniqueApplication::slotSplashTimeout()
{
  delete splash;
  delete sp;
  splash = 0L;
  sp = 0L;
}


void KQApplicationPrivate::init()
{
  if (quantaApp->quantaStarted)
  {
    quantaApp->slotEnableIdleTimer(false);
    quantaApp->setParserEnabled(false); //will be enabled in quantaApp->m_quantaInit->openLastFiles();
    quantaApp->m_quantaInit->initQuanta();
    quantaApp->show();

    TQString initialProject;
    TQStringList initialFiles;
    for (int i = 0; i < args->count(); i++ )
    {
      TQString arg = args->url(i).url();

      if(arg.findRev(TQRegExp(".+\\.webprj")) != -1)
        initialProject = arg;
      else
        initialFiles += arg;
    }
    quantaApp->m_quantaInit->loadInitialProject(initialProject);
    //recoverCrashed manages the autosaved copies
    quantaApp->m_quantaInit->recoverCrashed(initialFiles);

    for(TQStringList::Iterator it = initialFiles.begin();it != initialFiles.end();++it)
    {
      KURL url;
      QuantaCommon::setUrl(url, (*it));
      quantaApp->slotFileOpen(url, quantaApp->defaultEncoding());  // load initial files
    }
    quantaApp->m_quantaInit->openLastFiles();
  }
  args->clear();
  delete splash;
  splash = 0L;
  delete sp;
  sp = 0L;
  delete quantaApp->m_quantaInit;
  quantaApp->m_quantaInit = 0L;
  quantaApp->slotEnableIdleTimer(true);
}

#include "kqapp.moc"