source: SMSSender/src/main.cpp @ 58:685f1614c319

3.0
Last change on this file since 58:685f1614c319 was 58:685f1614c319, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
  • Send log output only on windows into a file (there is no stdin/out)
File size: 3.3 KB
Line 
1#include "ui/VCMain/vcmain.h"
2
3#include <QtGui>
4#include <QApplication>
5
6#include <QString>
7#include <QtPlugin>
8
9#include "business/BCSettings.h"
10#include "business/BCAccountManager.h"
11#include "business/BCGatewayManager.h"
12#include "business/BCLibraryLoader.h"
13
14//Q_IMPORT_PLUGIN(interfaces)
15
16#include <iostream>
17#include <fstream>
18
19using namespace std;
20
21ofstream logfile;
22
23void MyOutputHandler(QtMsgType type, const char *msg) {
24    switch (type) {
25        case QtDebugMsg:
26            logfile << QTime::currentTime().toString().toAscii().data() << " Debug: " << msg << "\n";
27            break;
28        case QtCriticalMsg:
29            logfile << QTime::currentTime().toString().toAscii().data() << " Critical: " << msg << "\n";
30            break;
31        case QtWarningMsg:
32            logfile << QTime::currentTime().toString().toAscii().data() << " Warning: " << msg << "\n";
33            break;
34        case QtFatalMsg:
35            logfile << QTime::currentTime().toString().toAscii().data() <<  " Fatal: " << msg << "\n";
36            abort();
37    }
38}
39
40
41void loadGateways() {
42    // TODO: Exception handling
43    QDir gatewayPath(qApp->applicationDirPath());
44    #if defined(Q_OS_WIN)
45        if (gatewayPath.dirName().toLower() == "debug" || gatewayPath.dirName().toLower() == "release")
46            gatewayPath.cdUp();
47    #elif defined(Q_OS_MAC)
48        if (gatewayPath.dirName() == "MacOS") {
49            gatewayPath.cdUp();
50            gatewayPath.cdUp();
51            gatewayPath.cdUp();
52        }
53    #endif
54    gatewayPath.cd("gateways");
55
56    BCGatewayManager::instance()->loadGatewaysFromLibraryPath(gatewayPath);
57}
58
59void loadAccounts() {
60    // TODO: Exception handling
61    BCAccountManager::instance()->readAccountsFromStorage();
62    BCAccountManager::instance()->accountLoadManager()->loadAccounts(BCAccountManager::instance()->getAccountList());
63}
64
65void sendTestSMS(){
66/*    IContact* c = BCContactManager::instance()->getContact(1);
67    QSet<IContact*> recipients;
68    recipients.insert(c);
69
70    IAccount* ac = BCAccountManager::instance()->getAccount(1);
71    ac->sendSMS("testmsg", recipients);*/
72}
73
74int main(int argc, char *argv[]){
75    #ifndef QT_NO_DEBUG_OUTPUT
76        logfile.open("logfile.txt", ios::app);
77        #if defined(Q_OS_WIN)
78        qInstallMsgHandler(MyOutputHandler);
79        #endif
80    #endif
81
82    QApplication a(argc, argv);
83
84    /* Load the translator */
85    QLocale locale = BCSettings::instance()->getLocale();
86
87    QTranslator qtTranslator;
88    qtTranslator.load("qt_" + locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
89    a.installTranslator(&qtTranslator);
90
91    QTranslator myTranslator;
92    if (myTranslator.load(locale.name(), BCSettings::instance()->getLocalePath())){
93        a.installTranslator(&myTranslator);
94    }
95
96    VCMain w;
97    /* Center the window */
98    int scrn = QApplication::desktop()->screenNumber(&w);
99    QRect desk(QApplication::desktop()->availableGeometry(scrn));
100    w.move((desk.width() - w.width()) / 2,
101           (desk.height() - w.height()) / 2);
102
103    /* And finally show it */
104    w.show();
105
106
107    loadGateways();
108
109    foreach (ILibrary* library, BCLibraryLoader::instance()->libraries()) {
110        QTranslator* translator = library->getTranslator(locale);
111        if (!translator->isEmpty()){
112            a.installTranslator(translator);
113        }
114    }
115
116    loadAccounts();
117
118    return a.exec();
119}
Note: See TracBrowser for help on using the repository browser.