Changeset 373:434967368de8 in SMSSender


Ignore:
Timestamp:
Apr 14, 2014 12:50:28 PM (5 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
separation-frontend-backend
Message:
  • Printing program output is now done in an own helper class.
  • Debug output is only printed when compiled with debug flags or having the --verbose command line argument set.
  • Introduces command line argument parsing.
Location:
frontend
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • frontend/business/settings_base.cpp

    r356 r373  
    2727    : m_storage(storage)
    2828    , ENCRYPT_PWD("d92voimod_:DowDiofpqldovD;Msin039Dmw93DiovdqQdopM049:")
     29#ifdef QT_DEBUG
     30    , m_verboseOutput(true)
     31#else
     32    , m_verboseOutput(false)
     33#endif
    2934{
    3035}
     36
     37/************************* Per-execution settings *****************************/
    3138
    3239const QDir BaseSettings::getLocalePath() const {
     
    7077}
    7178
     79bool BaseSettings::isVerboseOutput() const {
     80    return m_verboseOutput;
     81}
     82
     83void BaseSettings::setVerboseOutput(bool verbose) {
     84    if (isVerboseOutput() == verbose) return;
     85
     86    m_verboseOutput = verbose;
     87    emit settingChanged(VerboseOutput);
     88}
     89
     90/************************** Persistent settings *******************************/
     91
    7292bool BaseSettings::getCheckForUpdates(){
    7393    return m_storage->readBool("", "checkForUpdates", true);
  • frontend/business/settings_base.h

    r319 r373  
    3030public:
    3131    enum Setting {
    32         Locale = 0,
     32        // Per-execution
     33        VerboseOutput = 0,
    3334
    34         CheckForUpdates = 1,
    35         AddSuffix = 2,
    36         SMSSuffix = 3,
    37         ActiveAccountId = 4,
    38         ShowSentConfirmation = 5,
     35        // Persistent
     36        Locale = 1000,
    3937
    40         ProxyEnabled = 6,
    41         ProxyType = 7,
    42         ProxyHost = 8,
    43         ProxyPort = 9,
    44         ProxyAuthEnabled = 10,
    45         ProxyUsername = 11,
    46         ProxyPassword = 12,
     38        CheckForUpdates = 1001,
     39        AddSuffix = 1002,
     40        SMSSuffix = 1003,
     41        ActiveAccountId = 1004,
     42        ShowSentConfirmation = 1005,
     43
     44        ProxyEnabled = 1006,
     45        ProxyType = 1007,
     46        ProxyHost = 1008,
     47        ProxyPort = 1009,
     48        ProxyAuthEnabled = 1010,
     49        ProxyUsername = 1011,
     50        ProxyPassword = 1012,
    4751
    4852        LastSetting = ProxyPassword
     
    5256    explicit BaseSettings(::Persistence::IMainStorage *storage);
    5357
    54 public:
     58public: /* Per-execution settings */
    5559    const QDir     getLocalePath() const;
    5660    QLocale        getLocale();
    5761    QList<QLocale> getLocales();
    5862
     63    bool isVerboseOutput() const;
     64    void setVerboseOutput(bool verbose);
     65
     66public: /* Persistent settings */
    5967    bool    getCheckForUpdates();
    6068    bool    getAddSuffix();
     
    100108private:
    101109    const QString ENCRYPT_PWD;
     110
     111    bool m_verboseOutput;
    102112};
    103113
  • frontend/frontend-base.pro

    r366 r373  
    3434    business/groupmanager.h \
    3535    business/libraryloader_base.h \
     36    business/outputhelper.h \
    3637    business/settings.h \
    3738    business/settings_base.h \
     
    6061    business/groupmanager.cpp \
    6162    business/libraryloader_base.cpp \
     63    business/outputhelper.cpp \
    6264    business/settings_base.cpp \
    6365    business/suffixmanager.cpp \
  • frontend/gui/bootstrap.cpp

    r356 r373  
    2828#include "frontend/business/accountmanager.h"
    2929#include "frontend/business/gatewaymanager.h"
     30#include "frontend/business/outputhelper.h"
     31#include "frontend/business/settings.h"
    3032#include "frontend/business/suffixmanager.h"
    3133#include "frontend/gui/business/libraryloader.h"
     
    3941                                            m_managerFactory->contactImporterManager(), *m_persistenceFactory,
    4042                                            m_managerFactory->guiManager()));
     43    OutputHelper::init(m_managerFactory->settingsManager());
    4144
    4245    connect(m_managerFactory->settingsManager(), SIGNAL(settingChanged(int)),
     
    4952
    5053void Bootstrap::bootstrap() {
     54    parseCommandLineArguments(QCoreApplication::arguments());
     55
    5156    loadLibraries();
    5257
     
    5661
    5762    initAccounts();
     63}
     64
     65void Bootstrap::parseCommandLineArguments(const QStringList &arguments) {
     66    foreach (const QString &arg, arguments) {
     67        if (arg == "--verbose") {
     68            m_managerFactory->settingsManager()->setVerboseOutput(true);
     69        }
     70    }
    5871}
    5972
     
    125138
    126139/**
    127  * Crawls the directory 'kTranslationsPath' for files named
    128  * [prefix].[language].qm and adds them to the pool of available translation
    129  * files.
     140 * Crawls the locale path for files named [prefix].[language].qm and adds them
     141 * to the pool of available translation files.
    130142 */
    131143void Bootstrap::initTranslators() {
  • frontend/gui/bootstrap.h

    r356 r373  
    5757
    5858private:
     59    void parseCommandLineArguments(const QStringList &arguments);
     60
    5961    void loadLibraries();
    6062    void initAccounts();
  • frontend/gui/smssender-gui.cpp

    r317 r373  
    2323
    2424#include "common/domain/sversion.h"
    25 #include "frontend/business/settings.h"
    2625#include "frontend/gui/bootstrap.h"
    27 #include "frontend/gui/business/managerfactory.h"
    28 #include "frontend/gui/persistence/persistencefactory.h"
    2926#include "frontend/gui/ui/main.h"
    3027
    31 #include <iostream>
    32 #if defined(Q_OS_WIN)
    33 #include <fstream>
    34 
    35 std::ofstream logfile;
    36 
    37 void OutputHandler(QtMsgType type, const char *msg) {
    38     switch (type) {
    39 #ifndef QT_NO_DEBUG_OUTPUT
    40         case QtDebugMsg:
    41             logfile << QTime::currentTime().toString().toAscii().data() << " Debug: " << msg << std::endl;
    42             break;
    43 #endif
    44 #ifndef QT_NO_WARNING_OUTPUT
    45         case QtWarningMsg:
    46             logfile << QTime::currentTime().toString().toAscii().data() << " Warning: " << msg << std::endl;
    47             break;
    48 #endif
    49         case QtCriticalMsg:
    50             logfile << QTime::currentTime().toString().toAscii().data() << " Critical: " << msg << std::endl;
    51             break;
    52         case QtFatalMsg:
    53             logfile << QTime::currentTime().toString().toAscii().data() << " Fatal: " << msg << std::endl;
    54             abort();
    55     }
    56 }
    57 #else
    58 QMutex outputMutex(QMutex::NonRecursive);
    59 void OutputHandler(QtMsgType type, const char *msg) {
    60     QMutexLocker locker(&outputMutex);
    61 
    62     QString strMsg(msg);
    63     strMsg.remove('"');
    64 
    65     switch (type) {
    66         case QtDebugMsg: {
    67             std::cout << "DEBUG: " << qPrintable(strMsg) << std::endl;
    68             break;
    69         }
    70         case QtWarningMsg: {
    71             std::cout << "WARNING: " << qPrintable(strMsg) << std::endl;
    72             break;
    73         }
    74         case QtCriticalMsg: {
    75             std::cerr << "CRITICAL: " << qPrintable(strMsg) << std::endl;
    76             break;
    77         }
    78         case QtFatalMsg: {
    79             std::cerr << "FATAL: " << qPrintable(strMsg) << std::endl;
    80             abort();
    81         }
    82     }
    83 }
    84 #endif
    8528
    8629int main(int argc, char *argv[]) {
    87 #if defined(Q_OS_WIN)
    88     QFile::remove("logfile.txt");
    89     logfile.open("logfile.txt", ios::app);
    90 #endif
    91     qInstallMsgHandler(OutputHandler);
    92 
    93     Q_INIT_RESOURCE(common);
     30/*    Q_INIT_RESOURCE(common);
     31    Q_INIT_RESOURCE(common-gui);
     32    Q_INIT_RESOURCE(gateways-common);
     33    Q_INIT_RESOURCE(gateways-common-gui);*/
    9434
    9535    qRegisterMetaType<EException>("EException");
    96 
    9736
    9837    QApplication a(argc, argv);
Note: See TracChangeset for help on using the changeset viewer.