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
|
/***************************************************************************
* copyright : (C) 2003-2007 by Pascal Brachet *
* addons by Frederic Devernay <frederic.devernay@m4x.org> *
* addons by Luis Silvestre *
* http://www.xm1math.net/texmaker/ *
* *
* 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. *
* *
***************************************************************************/
#include "mostQtHeaders.h"
#include "texmaker.h"
#include "smallUsefulFunctions.h"
#if QT_VERSION >= 0x040400
#include <qtsingleapplication.h>
#else
#include "dsingleapplication.h"
#endif
#include <QSplashScreen>
#ifdef Q_WS_WIN
#include "windows.h"
typedef BOOL (*AllowSetForegroundWindowFunc)(DWORD);
#endif
#if QT_VERSION >= 0x040400
class TexmakerApp : public QtSingleApplication {
#else
class TexmakerApp : public QApplication {
#endif
protected:
bool event(QEvent *event);
public:
bool initialized;
QString delayedFileLoad;
Texmaker *mw; // Moved from private:
TexmakerApp(int & argc, char ** argv);
#if QT_VERSION >= 0x040400
TexmakerApp(QString &id,int & argc, char ** argv);
#endif
~TexmakerApp();
void init(QStringList &cmdLine); // This function does all the initialization instead of the constructor.
/*really slow global event logging:
bool notify(QObject* obj, QEvent* event){
qWarning(qPrintable(QString("%1 obj %2 named %3 typed %4 child of %5 received %6").arg(QTime::currentTime().toString("HH:mm:ss:zzz")).arg((long)obj,8,16).arg(obj->objectName()).arg(obj->metaObject()->className()).arg(obj->parent()?obj->parent()->metaObject()->className():"").arg(event->type())));
return QApplication::notify(obj,event);
}//*/
};
#if QT_VERSION >= 0x040400
TexmakerApp::TexmakerApp(int & argc, char ** argv) : QtSingleApplication(argc, argv) {
mw = 0;
initialized=false;
}
TexmakerApp::TexmakerApp(QString &id,int & argc, char ** argv) : QtSingleApplication(id,argc, argv) {
mw = 0;
initialized=false;
}
#else
TexmakerApp::TexmakerApp(int & argc, char ** argv) : QApplication(argc, argv) {
mw = 0;
initialized=false;
}
#endif
void TexmakerApp::init(QStringList &cmdLine) {
QPixmap pixmap(":/images/splash.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
processEvents();
mw = new Texmaker();
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
splash->finish(mw);
delete splash;
initialized = true;
if (!delayedFileLoad.isEmpty()) cmdLine << delayedFileLoad;
mw->executeCommandLine(cmdLine,true);
}
TexmakerApp::~TexmakerApp() {
if (mw) delete mw;
}
bool TexmakerApp::event(QEvent * event) {
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *oe = static_cast<QFileOpenEvent *>(event);
if (initialized) mw->load(oe->file());
else delayedFileLoad = oe->file();
event->accept();
return true;
}
return QApplication::event(event);
}
int main(int argc, char ** argv) {
// This is a dummy constructor so that the programs loads fast.
QStringList environment = QProcess::systemEnvironment();
QString user=environment.filter(QRegExp("^USERNAME=|^USER=",Qt::CaseInsensitive)).first();
if(!user.isEmpty()){
int l=user.indexOf("=",0);
user="_"+user.right(user.length()-l-1);
}
user=TEXSTUDIO+user;
#if QT_VERSION >= 0x040400
TexmakerApp a(user,argc, argv);
#else
TexmakerApp a(argc, argv);
DSingleApplication instance(user);
#endif
bool startAlways=false;
QStringList args = QCoreApplication::arguments();
QStringList cmdLine;
for (int i = 1; i < args.count(); ++i) {
QString cmdArgument = args[i];
if (cmdArgument.startsWith('-')) {
// various commands
if (cmdArgument == "--start-always")
startAlways = true;
else if ((cmdArgument == "-line" || cmdArgument == "--line") && (++i < args.count()))
cmdLine << "--line" << args[i];
else if ((cmdArgument == "-page" || cmdArgument == "--page") && (++i < args.count()))
cmdLine << "--page" << args[i];
else if (cmdArgument.startsWith("-"))
cmdLine << cmdArgument;
} else
cmdLine << QFileInfo(cmdArgument).absoluteFilePath();
}
if (!startAlways)
#if QT_VERSION >= 0x040400
if (a.isRunning()) {
#else
if (instance.isRunning()) {
#endif
#ifdef Q_WS_WIN
AllowSetForegroundWindowFunc asfw = (AllowSetForegroundWindowFunc)GetProcAddress(GetModuleHandleA("user32.dll"),"AllowSetForegroundWindow");
if (asfw) asfw(/*ASFW_ANY*/(DWORD)(-1));
#endif
#if QT_VERSION >= 0x040400
a.sendMessage(cmdLine.join("#!#"));
#else
instance.sendMessage(cmdLine.join("#!#"));
#endif
return 0;
}
a.setApplicationName( TEXSTUDIO );
a.init(cmdLine); // Initialization takes place only if there is no other instance running.
#if QT_VERSION >= 0x040400
QObject::connect(&a, SIGNAL(messageReceived(const QString &)),
a.mw, SLOT(onOtherInstanceMessage(const QString &)));
#else
QObject::connect(&instance, SIGNAL(messageReceived(const QString &)),
a.mw, SLOT(onOtherInstanceMessage(const QString &)));
#endif
return a.exec();
}
|