Example #1
0
// IMPROVE: Too long and messy main function. Should chop it up in logical pieces.
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QString mainQmlFile(QLatin1String("qml/main.qml"));
    if (argc >= 2) {
        if (QLatin1String("-conversionWarning") == argv[1]) {
            qDebug("Displaying conversion warning");
            mainQmlFile = QLatin1String("qml/mainConversionWarning.qml");
        } else if (QLatin1String("-multiRuleWarning") == argv[1]) {
            qDebug("Displaying multi-rule warning");
            mainQmlFile = QLatin1String("qml/mainMultiRuleWarning.qml");
        } else if (QLatin1String("-credentialWarning") == argv[1]) {
            qDebug("Displaying credential warning");
            mainQmlFile = QLatin1String("qml/mainCredentialWarning.qml");
        }
    }

    QScopedPointer<QApplication> app(createApplication(argc, argv));

    QTranslator translator;
    setupTranslations(app.data(), &translator);

    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    // Reduce flicker - maybe. I couldn't see any difference, but it didn't hurt
    // either. See http://blog.rburchell.com/2011/11/avoiding-graphics-flicker-in-qt-qml.html
    viewer->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer->setAttribute(Qt::WA_NoSystemBackground);
    viewer->viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer->viewport()->setAttribute(Qt::WA_NoSystemBackground);

    ProfileClient profileClient;
    ProfileMaticClient profileMaticClient;

    QmlProfilesModel qmlProfilesModel(&profileClient, QmlProfilesModel::ProfileType);
    QmlRuleUtil::initialize(&qmlProfilesModel);
    QmlDaysModel qmlDaysModel;
    QmlRulesModel qmlRulesModel(&profileMaticClient, &qmlProfilesModel);

    QmlBoolFilterModel qmlConditionEditVisibleModel(qmlRulesModel.getConditionEditModel(), QmlConditionEditModel::VisibleRole, false);
    QmlBoolFilterModel qmlConditionEditNonVisibleModel(qmlRulesModel.getConditionEditModel(), QmlConditionEditModel::VisibleRole, true);
    setupEditModel(qmlRulesModel.getConditionEditModel(), &qmlConditionEditVisibleModel);
    setupEditModel(qmlRulesModel.getConditionEditModel(), &qmlConditionEditNonVisibleModel);

    QmlBoolFilterModel qmlActionEditVisibleModel(qmlRulesModel.getActionEditModel(), QmlConditionEditModel::VisibleRole, false);
    QmlBoolFilterModel qmlActionEditNonVisibleModel(qmlRulesModel.getActionEditModel(), QmlConditionEditModel::VisibleRole, true);
    setupEditModel(qmlRulesModel.getActionEditModel(), &qmlActionEditVisibleModel);
    setupEditModel(qmlRulesModel.getActionEditModel(), &qmlActionEditNonVisibleModel);

    QmlBackend qmlBackend;
    QScopedPointer<QmlLocation> qmlLocation(QmlLocation::create());
    QmlNfcMobility qmlNfc;

    QmlApplicationsScanner qmlApplicationsScanner;
    QmlSelectedApplicationsModel qmlSelectedApplicationsModel(qmlRulesModel.getEditRule(), &qmlApplicationsScanner);
    QmlSortProxyModel qmlSelectedApplicationsSortedModel(&qmlSelectedApplicationsModel, QmlSelectedApplicationsModel::ApplicationName);
    QmlApplicationsModel qmlApplicationsModel;
    QmlApplicationScannerToModelAdapter qmlApplicationScannerToModelAdapter(&qmlApplicationsModel, &qmlApplicationsScanner);
    QmlSortProxyModel qmlApplicationsSortedModel(&qmlApplicationsModel, QmlApplicationsModel::ApplicationName);

    QDeclarativeContext *ctxt = viewer->rootContext();
    QDeclarativeEngine *engine = ctxt->engine();
    engine->connect(engine, SIGNAL(quit()), app.data(), SLOT(quit()));

    qmlRegisterType<Rule>("Rule", 1, 0, "Rule");
    qmlRegisterType<RuleCondition>("Rule", 1, 0, "RuleCondition");
    qmlRegisterType<RuleAction>("Rule", 1, 0, "RuleAction");
    qmlRegisterType<RuleActionApplication>("Rule", 1, 0, "RuleActionApplication");
    qmlRegisterType<RuleActionAlarm>("Rule", 1, 0, "RuleActionAlarm");
    qmlRegisterType<RuleConditionNFC>("Rule", 1, 0, "RuleConditionNFC");
    qmlRegisterType<RuleConditionBatteryLevel>("Rule", 1, 0, "RuleConditionBatteryLevel");
    qmlRegisterType<RuleConditionCalendar>("Rule", 1, 0, "RuleConditionCalendar");
    qmlRegisterType<RuleConditionTimeInterval>("Rule", 1, 0, "RuleConditionTimeInterval");
    qmlRegisterType<PresenceRule>("profilematic", 1, 0, "PresenceRule");
    qmlRegisterType<QmlNetworkInfo>("profilematic", 1, 0, "NetworkInfo");
    qmlRegisterType<QmlChoiseModel>("profilematic", 1, 0, "ChoiseModel");
#ifdef MEEGO_EDITION_HARMATTAN
    qmlRegisterType<QmlPresenceModelImpl>("profilematic", 1, 0, "AccountsModel");
#else
    qmlRegisterType<QmlPresenceModelStub>("profilematic", 1, 0, "AccountsModel");
#endif
    ctxt->setContextProperty("profileClient", &profileClient);
    ctxt->setContextProperty("backend", &qmlBackend);
    ctxt->setContextProperty("backendDaysModel", &qmlDaysModel);
    ctxt->setContextProperty("backendRulesModel", &qmlRulesModel);
    ctxt->setContextProperty("backendProfilesModel", &qmlProfilesModel);
    ctxt->setContextProperty("backendConditionEditModel", qmlRulesModel.getConditionEditModel());
    ctxt->setContextProperty("backendConditionEditVisibleModel", &qmlConditionEditVisibleModel);
    ctxt->setContextProperty("backendConditionEditNonVisibleModel", &qmlConditionEditNonVisibleModel);
    ctxt->setContextProperty("backendActionEditModel", qmlRulesModel.getActionEditModel());
    ctxt->setContextProperty("backendActionEditVisibleModel", &qmlActionEditVisibleModel);
    ctxt->setContextProperty("backendActionEditNonVisibleModel", &qmlActionEditNonVisibleModel);
    ctxt->setContextProperty("backendLocation", qmlLocation.data());
    ctxt->setContextProperty("backendNfc", &qmlNfc);
    ctxt->setContextProperty("backendRuleUtil", QmlRuleUtil::instance());
    ctxt->setContextProperty("backendApplicationsModel", &qmlApplicationsModel);
    ctxt->setContextProperty("backendApplicationsSortedModel", &qmlApplicationsSortedModel);
    ctxt->setContextProperty("backendApplicationsScanner", &qmlApplicationScannerToModelAdapter);
    ctxt->setContextProperty("backendSelectedApplicationsModel", &qmlSelectedApplicationsModel);
    ctxt->setContextProperty("backendSelectedApplicationsSortedModel", &qmlSelectedApplicationsSortedModel);

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile(mainQmlFile);
    viewer->showExpanded();

    int retVal = app->exec();
    qDebug("Exiting with return value %d", retVal);
    QmlRuleUtil::deinitialize();

    return retVal;
}
Example #2
0
Application::Application(int &argc, char **argv) :
    SharedTools::QtSingleApplication(argc, argv),
    _tray(0),
#if QT_VERSION >= 0x040700
    _networkMgr(new QNetworkConfigurationManager(this)),
#endif
    _sslErrorDialog(0),
    _contextMenu(0),
    _theme(Theme::instance()),
    _updateDetector(0),
    _logBrowser(0),
    _showLogWindow(false),
    _logFlush(false),
    _helpOnly(false),
    _fileItemDialog(0)
{
    setApplicationName( _theme->appNameGUI() );
    setWindowIcon( _theme->applicationIcon() );

    parseOptions(arguments());
    setupTranslations();
    setupLogBrowser();
    //no need to waste time;
    if ( _helpOnly ) return;

#ifdef Q_OS_LINUX
        // HACK: bump the refcount for libgnutls by calling dlopen()
        // so gnutls, which is an dependency of libneon on some linux
        // distros, and does not cleanup it's FDs properly, does
        // not get unloaded. This works around a FD exhaustion crash
        // (#154). We are not using gnutls at all and it's fine
        // if loading fails, so no error handling is performed here.
        dlopen("libgnutls.so", RTLD_LAZY|RTLD_NODELETE);
#endif

    connect( this, SIGNAL(messageReceived(QString)), SLOT(slotParseOptions(QString)));
    connect( Logger::instance(), SIGNAL(guiLog(QString,QString)),
             this, SLOT(slotShowTrayMessage(QString,QString)));
    // create folder manager for sync folder management
    _folderMan = new FolderMan(this);
    connect( _folderMan, SIGNAL(folderSyncStateChange(QString)),
             this,SLOT(slotSyncStateChange(QString)));
    _folderMan->setSyncEnabled(false);

    /* use a signal mapper to map the open requests to the alias names */
    _folderOpenActionMapper = new QSignalMapper(this);
    connect(_folderOpenActionMapper, SIGNAL(mapped(const QString &)),
            this, SLOT(slotFolderOpenAction(const QString &)));

    setQuitOnLastWindowClosed(false);

    _folderWizard = new FolderWizard;

    _owncloudSetupWizard = new OwncloudSetupWizard( _folderMan, _theme, this );
    connect( _owncloudSetupWizard, SIGNAL(ownCloudWizardDone(int)),
             this, SLOT(slotownCloudWizardDone(int)));

    _statusDialog = new StatusDialog( _theme );
    connect( _statusDialog, SIGNAL(addASync()), this, SLOT(slotAddFolder()) );

    connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
             SLOT(slotRemoveFolder(const QString&)));
    connect( _statusDialog, SIGNAL(enableFolderAlias(QString,bool)),
             SLOT(slotEnableFolder(QString,bool)));
    connect( _statusDialog, SIGNAL(infoFolderAlias(const QString&)),
             SLOT(slotInfoFolder( const QString&)));
    connect( _statusDialog, SIGNAL(openFolderAlias(const QString&)),
             SLOT(slotFolderOpenAction(QString)));

#if 0
#if QT_VERSION >= 0x040700
    qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");
    foreach (const QNetworkConfiguration& netCfg, _networkMgr->allConfigurations(QNetworkConfiguration::Active)) {
        //qDebug() << "Network:" << netCfg.identifier();
    }
#endif
#endif
    setupActions();
    setupSystemTray();
    setupProxy();


    int cnt = _folderMan->setupFolders();
    _statusDialog->setFolderList( _folderMan->map() );

    QObject::connect( this, SIGNAL(messageReceived(QString)),
                         this, SLOT(slotOpenStatus()) );

    QTimer::singleShot( 0, this, SLOT( slotStartFolderSetup() ));

    MirallConfigFile cfg;
    if( !cfg.ownCloudSkipUpdateCheck() ) {
        QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
    }

    connect( ownCloudInfo::instance(), SIGNAL(sslFailed(QNetworkReply*, QList<QSslError>)),
             this,SLOT(slotSSLFailed(QNetworkReply*, QList<QSslError>)));

    qDebug() << "Network Location: " << NetworkLocation::currentLocation().encoded();
}
Example #3
0
Application::Application(int &argc, char **argv) :
    SharedTools::QtSingleApplication(argc, argv),
    _tray(0),
#if QT_VERSION >= 0x040700
    _networkMgr(new QNetworkConfigurationManager(this)),
#endif
    _sslErrorDialog(0),
    _contextMenu(0),
    _theme(Theme::instance()),
    _updateDetector(0),
    _logBrowser(0),
    _showLogWindow(false),
    _logFlush(false),
    _helpOnly(false),
    _fileItemDialog(0),
    _statusDialog(0)
{
    setApplicationName( _theme->appNameGUI() );
    setWindowIcon( _theme->applicationIcon() );

    parseOptions(arguments());
    setupTranslations();
    setupLogBrowser();
    //no need to waste time;
    if ( _helpOnly ) return;

    connect( this, SIGNAL(messageReceived(QString)), SLOT(slotParseOptions(QString)));
    connect( Logger::instance(), SIGNAL(guiLog(QString,QString)),
             this, SLOT(slotShowTrayMessage(QString,QString)));
    // create folder manager for sync folder management
    _folderMan = new FolderMan(this);
    connect( _folderMan, SIGNAL(folderSyncStateChange(QString)),
             this,SLOT(slotSyncStateChange(QString)));
    _folderMan->setSyncEnabled(false);

    /* use a signal mapper to map the open requests to the alias names */
    _folderOpenActionMapper = new QSignalMapper(this);
    connect(_folderOpenActionMapper, SIGNAL(mapped(const QString &)),
            this, SLOT(slotFolderOpenAction(const QString &)));

    setQuitOnLastWindowClosed(false);

    _folderWizard = new FolderWizard;

    _owncloudSetupWizard = new OwncloudSetupWizard( _folderMan, _theme, this );
    connect( _owncloudSetupWizard, SIGNAL(ownCloudWizardDone(int)),
             this, SLOT(slotownCloudWizardDone(int)));

    _statusDialog = new StatusDialog( _theme );
    connect( _statusDialog, SIGNAL(addASync()), this, SLOT(slotAddFolder()) );

    connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
             SLOT(slotRemoveFolder(const QString&)));
    connect( _statusDialog, SIGNAL(enableFolderAlias(QString,bool)),
             SLOT(slotEnableFolder(QString,bool)));
    connect( _statusDialog, SIGNAL(infoFolderAlias(const QString&)),
             SLOT(slotInfoFolder( const QString&)));
    connect( _statusDialog, SIGNAL(openFolderAlias(const QString&)),
             SLOT(slotFolderOpenAction(QString)));

#if 0
#if QT_VERSION >= 0x040700
    qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");
    foreach (const QNetworkConfiguration& netCfg, _networkMgr->allConfigurations(QNetworkConfiguration::Active)) {
        //qDebug() << "Network:" << netCfg.identifier();
    }
#endif
#endif
    setupActions();
    setupSystemTray();
    setupProxy();


    int cnt = _folderMan->setupFolders();
    _statusDialog->setFolderList( _folderMan->map() );

    QObject::connect( this, SIGNAL(messageReceived(QString)),
                         this, SLOT(slotOpenStatus()) );

    QTimer::singleShot( 0, this, SLOT( slotStartFolderSetup() ));

    MirallConfigFile cfg;
    if( !cfg.ownCloudSkipUpdateCheck() ) {
        QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
    }

    connect( ownCloudInfo::instance(), SIGNAL(sslFailed(QNetworkReply*, QList<QSslError>)),
             this,SLOT(slotSSLFailed(QNetworkReply*, QList<QSslError>)));

    qDebug() << "Network Location: " << NetworkLocation::currentLocation().encoded();
}
Example #4
0
/* Constructor setups the GUI. */
QucsTranscalc::QucsTranscalc() {
    
  QWidget *centralWidget = new QWidget(this);  
  setCentralWidget(centralWidget);
  
  // set application icon
  setWindowIcon(QPixmap(":/bitmaps/big.qucs.xpm"));
  setWindowTitle("Qucs Transcalc " PACKAGE_VERSION);

  // create file menu
  QMenu *fileMenu = new QMenu(tr("&File"));

  QAction *fileLoad = new QAction(tr("&Load"), this);
  fileLoad->setShortcut(Qt::CTRL+Qt::Key_L);
  fileMenu->addAction(fileLoad);
  connect(fileLoad, SIGNAL(activated()), SLOT(slotFileLoad()));

  QAction *fileSave = new QAction (tr("&Save"), this);
  fileSave->setShortcut(Qt::CTRL+Qt::Key_S);
  fileMenu->addAction(fileSave);
  connect(fileSave, SIGNAL(activated()), SLOT(slotFileSave()));

  fileMenu->addSeparator();

  QAction *fileOption = new QAction (tr("&Options"), this);
  fileOption->setShortcut(Qt::CTRL+Qt::Key_O);
  fileMenu->addAction(fileOption);
  connect(fileOption, SIGNAL(activated()), SLOT(slotOptions()));

  fileMenu->addSeparator();

  QAction *fileQuit = new QAction (tr("&Quit"), this);
  fileQuit->setShortcut(Qt::CTRL+Qt::Key_Q);
  fileMenu->addAction(fileQuit);
  connect(fileQuit, SIGNAL(activated()), SLOT(slotQuit()));

  // create execute menu
  QMenu *execMenu = new QMenu(tr("&Execute"));

  QAction *execCopy = new QAction(tr("&Copy to Clipboard"), this);
  execCopy->setShortcut(Qt::Key_F2);
  execMenu->addAction(execCopy);
  connect(execCopy, SIGNAL(activated()), SLOT(slotCopyToClipBoard()));

  QAction *execAnalyze = new QAction(tr("&Analyze"), this);
  execAnalyze->setShortcut(Qt::Key_F3);
  execMenu->addAction(execAnalyze);
  connect(execAnalyze, SIGNAL(activated()), SLOT(slotAnalyze()));

  QAction *execSynthesize = new QAction (tr("&Synthesize"), this);
  execSynthesize->setShortcut(Qt::Key_F4);
  execMenu->addAction(execSynthesize);
  connect(execSynthesize, SIGNAL(activated()), SLOT(slotSynthesize()));

  // create help menu
  QMenu *helpMenu = new QMenu(tr("&Help"));
  QAction *helpHelp = new QAction(tr("&Help"), this);
  helpHelp->setShortcut(Qt::Key_F1);
  helpMenu->addAction(helpHelp);
  connect(helpHelp, SIGNAL(activated()), SLOT(slotHelpIntro()));

  QAction *helpAbout = new QAction(tr("About"), this);
  helpMenu->addAction(helpAbout);
  connect(helpAbout, SIGNAL(activated()), SLOT(slotAbout()));

  // setup menu bar
  menuBar()->addMenu(fileMenu);
  menuBar()->addMenu(execMenu);
  menuBar()->addSeparator();
  menuBar()->addMenu(helpMenu);

  // === left
  // seletion combo and figure
  QVBoxLayout *vl = new QVBoxLayout();

  // transmission line type choice
  QGroupBox * lineGroup = new QGroupBox (tr("Transmission Line Type"));
  tranType = new QComboBox (lineGroup);
  tranType->insertItem (0, tr("Microstrip Line"));
  tranType->insertItem (1, tr("Coplanar Waveguide"));
  tranType->insertItem (2, tr("Grounded Coplanar"));
  tranType->insertItem (3, tr("Rectangular Waveguide"));
  tranType->insertItem (4, tr("Coaxial Line"));
  tranType->insertItem (5, tr("Coupled Microstrip"));
  connect(tranType, SIGNAL(activated(int)), SLOT(slotSelectType(int)));
  // setup transmission line picture
  pix = new QLabel (lineGroup);
  pix->setPixmap(QPixmap(":/bitmaps/microstrip.png"));

  QVBoxLayout *vfig = new QVBoxLayout();
  vfig->addWidget(tranType);
  vfig->addWidget(pix);
  vfig->setSpacing(3);
  lineGroup->setLayout(vfig);

  vl->addWidget(lineGroup);

  // init additional translations
  setupTranslations ();

  // set current mode
  mode = ModeMicrostrip;

  // === middle
  QVBoxLayout *vm = new QVBoxLayout();
  vm->setSpacing (3);

  // substrate parameter box
  QGroupBox * substrate = new QGroupBox (tr("Substrate Parameters"));
  vm->addWidget(substrate);

  // Pass the GroupBox > create Grid layout > Add widgets > set layout
  createPropItems (substrate, TRANS_SUBSTRATE);

  // component parameter box
  QGroupBox * component = new QGroupBox (tr("Component Parameters"));
  vm->addWidget(component);
  createPropItems (component, TRANS_COMPONENT);


  // === right
  QVBoxLayout *vr = new QVBoxLayout();
  vr->setSpacing (3);

  // physical parameter box
  QGroupBox * physical = new QGroupBox (tr("Physical Parameters"));
  vr->addWidget(physical);
  createPropItems (physical, TRANS_PHYSICAL);

  // analyze/synthesize buttons
  QHBoxLayout * h2 = new QHBoxLayout();
  QPushButton * analyze = new QPushButton (tr("Analyze"));
  h2->addWidget(analyze);
  analyze->setToolTip(tr("Derive Electrical Parameters"));
  connect(analyze, SIGNAL(clicked()), SLOT(slotAnalyze()));

  QPushButton * synthesize = new QPushButton (tr("Synthesize"));
  h2->addWidget(synthesize);
  synthesize->setToolTip(tr("Compute Physical Parameters"));
  connect(synthesize, SIGNAL(clicked()), SLOT(slotSynthesize()));
  vr->addLayout(h2);

  // electrical parameter box
  QGroupBox * electrical = new QGroupBox (tr("Electrical Parameters"));
  vr->addWidget(electrical);
  createPropItems (electrical, TRANS_ELECTRICAL);

  calculated = new QGroupBox (tr("Calculated Results"));
  vr->addWidget(calculated);

  // status line
  //statBar = new QStatusBar (this);
  //QLabel * statText = new QLabel ("Ready.", statBar);
  statusBar()->showMessage (tr("Ready."));
  //statBar->setFixedHeight (statText->height ());
  //delete statText;

  QVBoxLayout *vmain = new QVBoxLayout();

  QHBoxLayout *hmain = new QHBoxLayout();
  hmain->addLayout(vl);
  hmain->addLayout(vm);
  hmain->addLayout(vr);

  vmain->addLayout(hmain);
  //vmain->addWidget(statBar);
  
  centralWidget->setLayout(vmain);
  
  // setup calculated result bix
  createResultItems (calculated);
  updateSelection ();

  // instantiate transmission lines
  TransLineTypes[0].line = new microstrip ();
  TransLineTypes[0].line->setApplication (this);
  TransLineTypes[1].line = new coplanar ();
  TransLineTypes[1].line->setApplication (this);
  TransLineTypes[2].line = new groundedCoplanar ();
  TransLineTypes[2].line->setApplication (this);
  TransLineTypes[3].line = new rectwaveguide ();
  TransLineTypes[3].line->setApplication (this);
  TransLineTypes[4].line = new coax ();
  TransLineTypes[4].line->setApplication (this);
  TransLineTypes[5].line = new c_microstrip ();
  TransLineTypes[5].line->setApplication (this);
}