source: SMSSender/src/main.cpp @ 54:03426342db84

3.0
Last change on this file since 54:03426342db84 was 54:03426342db84, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
  • qDebug() saved into a file.
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    logfile.open("logfile.txt", ios::app);
76    #ifndef QT_NO_DEBUG_OUTPUT
77    qInstallMsgHandler(MyOutputHandler);
78    #endif
79
80
81    QApplication a(argc, argv);
82
83    /* Load the translator */
84    QLocale locale = BCSettings::instance()->getLocale();
85
86    QTranslator qtTranslator;
87    qtTranslator.load("qt_" + locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
88    a.installTranslator(&qtTranslator);
89
90    QTranslator myTranslator;
91    if (myTranslator.load(locale.name(), BCSettings::instance()->getLocalePath())){
92        a.installTranslator(&myTranslator);
93    }
94
95    VCMain w;
96    /* Center the window */
97    int scrn = QApplication::desktop()->screenNumber(&w);
98    QRect desk(QApplication::desktop()->availableGeometry(scrn));
99    w.move((desk.width() - w.width()) / 2,
100           (desk.height() - w.height()) / 2);
101
102    /* And finally show it */
103    w.show();
104
105
106    loadGateways();
107
108    foreach (ILibrary* library, BCLibraryLoader::instance()->libraries()) {
109        QTranslator* translator = library->getTranslator(locale);
110        if (!translator->isEmpty()){
111            a.installTranslator(translator);
112        }
113    }
114
115    loadAccounts();
116
117    return a.exec();
118}
Note: See TracBrowser for help on using the repository browser.