bool ApplicationCore::configure() { if (CONFIGURATION.failure == true) { qDebug() << "ApplicationCore::configure: an error was found within the configuration."; if (!CONFIGURATION.failureMessage.isEmpty()) { showInformation(tr("Configuration Problem"), CONFIGURATION.failureMessage); CONFIGURATION.failureMessage.clear(); } } // load configuration: QSettings settings; settings.beginGroup(CONFIGURATION.configurationName); bool configurationComplete = CONFIGURATION.readFrom(settings); if (!configurationComplete || CONFIGURATION.failure) { qDebug() << "ApplicationCore::configure: no complete configuration found for configuration name" << CONFIGURATION.configurationName; // FIXME maybe move to Configuration::loadDefaults const QString storageDatabaseDirectory = charmDataDir(); const QString storageDatabaseFileRelease = QStringLiteral("Charm.db"); const QString storageDatabaseFileDebug = QStringLiteral("Charm_debug.db"); const QString storageDatabaseRelease = storageDatabaseDirectory + storageDatabaseFileRelease; const QString storageDatabaseDebug = storageDatabaseDirectory + storageDatabaseFileDebug; QString storageDatabase; #ifdef NDEBUG Q_UNUSED(storageDatabaseDebug); storageDatabase = storageDatabaseRelease; #else Q_UNUSED(storageDatabaseRelease); storageDatabase = storageDatabaseDebug; #endif CONFIGURATION.localStorageDatabase = QDir::toNativeSeparators(storageDatabase); ConfigurationDialog dialog(CONFIGURATION, &mainView()); if (dialog.exec()) { CONFIGURATION = dialog.configuration(); CONFIGURATION.writeTo(settings); mainView().show(); } else { qDebug() << "ApplicationCore::configure: user cancelled configuration. Exiting."; // quit(); return false; } } return true; }
void STNewAccountAuthorizeView::fadeAnimated(float v){ setOpacity(m_fadeAnimation->value()*m_cancelAnimation->value()); this->setFocus(); relayout(); if(m_cancelAnimation->value()==0.f){ // canceled or done. processAddedAccount(); this->deleteLater(); }else if(!wasCancelled()){ if(m_fadeAnimation->value()==1.f){ if(!m_authView){ // authoization start!! m_authView=new STAuthorizeView(); QRectF rt(10,36,320,413); rt.translate(m_window->offset()); rt.translate(m_window->pos()); mainView()->startAuthorizeView(m_authView, (m_cancelButton->pos()+m_window->pos()).toPoint(), rt.toRect()); connect(m_authView, SIGNAL(cancelled()), this, SLOT(cancelled())); QUrl userAuthURL("https://api.twitter.com/oauth/authorize"); QPair<QString, QString> tokenParam = qMakePair(QString("oauth_token"), m_temporaryTokenString); QUrl openWebPageUrl(userAuthURL.toString(), QUrl::StrictMode); openWebPageUrl.addQueryItem(tokenParam.first, tokenParam.second); openWebPageUrl.addQueryItem("force_login", "true"); m_authView->setUrl(openWebPageUrl); } } } }
void STNewAccountAuthorizeView::cancelled(){ if(m_authView){ mainView()->stopAuthorizeView(m_authView); m_authView->deleteLater();; m_authView=NULL; } if(m_manager){ m_manager->abortCurrentRequest();; m_manager->deleteLater(); m_manager=NULL; } if(m_request){ m_request->deleteLater();; m_request=NULL; } close(); }
void STNewAccountAuthorizeView::authorizationReceived(QString, QString){ if(m_manager->lastError()!=KQOAuthManager::NoError){ // error! // TODO: show error cancelled(); return; } if(m_authView){ mainView()->stopAuthorizeView(m_authView); m_authView->deleteLater();; m_authView=NULL; } m_animView->setVisible(true); m_manager->getUserAccessTokens(QUrl("https://api.twitter.com/oauth/access_token")); }
void mainModel(bool updated) { //Updated means to update whole screen. Therefore: updated = TRUE >> update whole screen if (!updated) { //data = getSerialData(END_CHAR); mainView(data); } else { strcpy(screenTitle, "MAIN SCREEN"); strcpy(information, "ArduRC Team!"); strcpy(prevScreen, "altitude"); strcpy(nextScreen, "temp"); mainViewUpdate(screenTitle, information, prevScreen, nextScreen); } }
void HistoryItem::destroy() { if (isLogEntry()) { Assert(!mainView()); } else { // All this must be done for all items manually in History::clear()! eraseFromUnreadMentions(); if (IsServerMsgId(id)) { if (const auto types = sharedMediaTypes()) { _history->session().storage().remove(Storage::SharedMediaRemoveOne( _history->peer->id, types, id)); } } else { _history->session().api().cancelLocalItem(this); } _history->itemRemoved(this); } delete this; }
void HistoryItem::removeMainView() { if (const auto view = mainView()) { _history->owner().notifyHistoryChangeDelayed(_history); view->removeFromBlock(); } }
Application::Application(int& argc, char** argv) : QApplication( argc, argv ) , m_closedWindow( 0 ) , m_actionStopAllTasks( this ) , m_windows( QList<CharmWindow*> () << &m_tasksWindow << &m_eventWindow << &m_timeTracker ) , m_actionQuit( this ) , m_state(Constructed) , m_actionAboutDialog( this ) , m_actionPreferences( this ) , m_actionExportToXml( this ) , m_actionImportFromXml( this ) , m_actionSyncTasks( this ) , m_actionImportTasks( this ) , m_actionExportTasks( this ) , m_actionEnterVacation( this ) , m_actionActivityReport( this ) , m_actionWeeklyTimesheetReport( this ) , m_actionMonthlyTimesheetReport( this ) , m_idleDetector( 0 ) , m_timeTrackerHiddenFromSystrayToggle( false ) , m_tasksWindowHiddenFromSystrayToggle( false ) , m_eventWindowHiddenFromSystrayToggle( false ) , m_dateChangeWatcher( new DateChangeWatcher( this ) ) { // QApplication setup setQuitOnLastWindowClosed(false); // application metadata setup // note that this modifies the behaviour of QSettings: QCoreApplication::setOrganizationName("KDAB"); QCoreApplication::setOrganizationDomain("kdab.com"); QCoreApplication::setApplicationName("Charm"); QCoreApplication::setApplicationVersion(CHARM_VERSION); QLocalSocket uniqueApplicationSocket; QString serverName( "com.kdab.charm" ); #ifndef NDEBUG serverName.append( "_debug" ); #endif uniqueApplicationSocket.connectToServer(serverName, QIODevice::ReadOnly); if (uniqueApplicationSocket.waitForConnected(1000)) throw AlreadyRunningException(); connect(&m_uniqueApplicationServer, SIGNAL(newConnection()), this, SLOT(slotHandleUniqueApplicationConnection())); QFile::remove(QDir::tempPath() + '/' + serverName); bool listening = m_uniqueApplicationServer.listen(serverName); if (!listening) qDebug() << "Failed to create QLocalServer for unique application support:" << m_uniqueApplicationServer.errorString(); Q_INIT_RESOURCE(CharmResources); Q_ASSERT_X(m_instance == 0, "Application ctor", "Application is a singleton and cannot be created more than once"); m_instance = this; qRegisterMetaType<State> ("State"); qRegisterMetaType<Event> ("Event"); // exit process (app will only exit once controller says it is ready) connect(&m_controller, SIGNAL(readyToQuit()), SLOT( slotControllerReadyToQuit())); connectControllerAndModel(&m_controller, m_model.charmDataModel()); connectControllerAndView(&m_controller, &mainView()); Q_FOREACH( CharmWindow* window, m_windows ) { if ( window != &mainView() ) { // main view acts as the main relay connect( window, SIGNAL( emitCommand( CharmCommand* ) ), &mainView(), SLOT( sendCommand( CharmCommand* ) ) ); connect( window, SIGNAL( emitCommandRollback( CharmCommand* ) ), &mainView(), SLOT( sendCommandRollback( CharmCommand* ) ) ); } // save the configuration (configuration is managed by the application) connect( window, SIGNAL(saveConfiguration() ), SLOT( slotSaveConfiguration() ) ); connect( window, SIGNAL( visibilityChanged( bool ) ), this, SLOT( slotCharmWindowVisibilityChanged( bool ) ) ); }
m_systrayContextMenu.addSeparator(); m_systrayContextMenu.addMenu( m_timeTracker.menu() ); m_systrayContextMenu.addSeparator(); m_systrayContextMenu.addAction( &m_actionQuit ); // set up actions: m_actionQuit.setShortcut( Qt::CTRL + Qt::Key_Q ); m_actionQuit.setText( tr( "Quit" ) ); m_actionQuit.setIcon( Data::quitCharmIcon() ); connect( &m_actionQuit, SIGNAL( triggered( bool ) ), SLOT( slotQuitApplication() ) ); m_actionAboutDialog.setText( tr( "About Charm" ) ); connect( &m_actionAboutDialog, SIGNAL( triggered() ), &mainView(), SLOT( slotAboutDialog() ) ); m_actionPreferences.setText( tr( "Preferences" ) ); m_actionPreferences.setIcon( Data::configureIcon() ); connect( &m_actionPreferences, SIGNAL( triggered( bool ) ), &mainView(), SLOT( slotEditPreferences( bool ) ) ); m_actionPreferences.setEnabled( true ); m_actionImportFromXml.setText( tr( "Import Database from Previous Export..." ) ); connect( &m_actionImportFromXml, SIGNAL( triggered() ), &mainView(), SLOT( slotImportFromXml() ) ); m_actionExportToXml.setText( tr( "Export Database..." ) ); connect( &m_actionExportToXml, SIGNAL( triggered() ), &mainView(), SLOT( slotExportToXml() ) ); m_actionSyncTasks.setText( tr( "Download Task Definitions..." ) ); connect( &m_actionSyncTasks, SIGNAL( triggered() ),
int main(int argc, char *argv[]) { Settings settings; bool resolutionFromCmdLine = false; if (!readSettingsFromCommandLine(argc, argv, settings)) return 1; if (settings.size().width() > 0 && settings.size().height() > 0) resolutionFromCmdLine = true; // Start measuring here QTime t; t.start(); QApplication app(argc, argv); app.setApplicationName("GraphicsViewBenchmark"); MainView mainView(settings.options().testFlag(Settings::UseOpenGL), settings.options().testFlag(Settings::OutputFps)); if ((settings.angle() % 360) != 0) mainView.rotateContent(settings.angle()); if (resolutionFromCmdLine) { mainView.resize(settings.size().width(), settings.size().height()); mainView.show(); } else { #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) mainView.showFullScreen(); #else mainView.resize(360, 640); mainView.show(); #endif } // Stop measuring here int creationTime = t.elapsed(); qRegisterMetaType<Theme::Themes>("Theme::Themes"); qRegisterMetaType<Benchmark::ListType>("Benchmark::ListType"); qRegisterMetaType<TestFunctionResult*>("TestFunctionResult*"); qRegisterMetaType<Benchmark*>("Benchmark*"); qRegisterMetaType<ScriptRunner*>("ScriptRunner*"); qRegisterMetaType<ResultLogger*>("ResultLogger*"); TestController tc(settings.outputFileName(), &mainView, ResultLogger::ResultFormat(settings.resultFormat())); if (settings.options().testFlag(Settings::UseListItemCache)) tc.setSubtreeCache(true); if(settings.options().testFlag(Settings::NoResourceUsage)) tc.setCpuMemLogging(false); TestThread *tt = new ScriptRunner(settings.scriptName(), &tc, &app); tt->addTestFunctionBenchmark("Startup", "Creation time of application and main window (ms).", creationTime); QTimer::singleShot(500, tt, SLOT(start())); int val = app.exec(); tt->wait(); delete tt; return val; }
ApplicationCore::ApplicationCore(TaskId startupTask, bool hideAtStart, QObject *parent) : QObject(parent) , m_actionStopAllTasks(this) , m_actionQuit(this) , m_actionAboutDialog(this) , m_actionPreferences(this) , m_actionExportToXml(this) , m_actionImportFromXml(this) , m_actionSyncTasks(this) , m_actionImportTasks(this) , m_actionExportTasks(this) , m_actionCheckForUpdates(this) , m_actionEnterVacation(this) , m_actionActivityReport(this) , m_actionWeeklyTimesheetReport(this) , m_actionMonthlyTimesheetReport(this) , m_uiElements( { &m_timeTracker, &m_tasksView, &m_eventView }), m_startupTask(startupTask) , m_hideAtStart(hideAtStart) #ifdef Q_OS_WIN , m_windowsJumpList(new QWinJumpList(this)) #endif , m_dateChangeWatcher(new DateChangeWatcher(this)) { // QApplication setup QApplication::setQuitOnLastWindowClosed(false); // application metadata setup // note that this modifies the behaviour of QSettings: QCoreApplication::setOrganizationName(QStringLiteral("KDAB")); QCoreApplication::setOrganizationDomain(QStringLiteral("kdab.com")); QCoreApplication::setApplicationName(QStringLiteral("Charm")); QCoreApplication::setApplicationVersion(CharmVersion()); QLocalSocket uniqueApplicationSocket; QString serverName(QStringLiteral("com.kdab.charm")); QString charmHomeEnv(QString::fromLocal8Bit(qgetenv("CHARM_HOME"))); if (!charmHomeEnv.isEmpty()) { serverName.append(QStringLiteral("_%1").arg( charmHomeEnv.replace(QRegExp(QLatin1String(":?/|:?\\\\")), QStringLiteral("_")))); } #ifndef NDEBUG serverName.append(QStringLiteral("_debug")); #endif uniqueApplicationSocket.connectToServer(serverName, QIODevice::ReadWrite); if (uniqueApplicationSocket.waitForConnected(1000)) { QByteArray command; if (startupTask != -1) { command = StartTaskCommand + QByteArray::number(startupTask); } else { command = RaiseWindowCommand; } command += '\n'; qint64 written = uniqueApplicationSocket.write(command); if (written == -1 || written != command.length()) { qWarning() << "Failed to pass " << command << " to running charm instance, error: " << uniqueApplicationSocket.errorString(); } uniqueApplicationSocket.flush(); uniqueApplicationSocket.waitForBytesWritten(); throw AlreadyRunningException(); } connect(&m_uniqueApplicationServer, &QLocalServer::newConnection, this, &ApplicationCore::slotHandleUniqueApplicationConnection, Qt::QueuedConnection); QFile::remove(QDir::tempPath() + QLatin1Char('/') + serverName); bool listening = m_uniqueApplicationServer.listen(serverName); if (!listening) qDebug() << "Failed to create QLocalServer for unique application support:" << m_uniqueApplicationServer.errorString(); Q_INIT_RESOURCE(CharmResources); Q_ASSERT_X(m_instance == 0, "Application ctor", "Application is a singleton and cannot be created more than once"); m_instance = this; qRegisterMetaType<State>("State"); qRegisterMetaType<Event>("Event"); // exit process (app will only exit once controller says it is ready) connect(&m_controller, &Controller::readyToQuit, this, &ApplicationCore::slotControllerReadyToQuit); connectControllerAndModel(&m_controller, m_model.charmDataModel()); Charm::connectControllerAndView(&m_controller, &m_timeTracker); // save the configuration (configuration is managed by the application) connect(&m_timeTracker, &CharmWindow::saveConfiguration, this, &ApplicationCore::slotSaveConfiguration); connect(&m_timeTracker, &TimeTrackingWindow::showNotification, this, &ApplicationCore::slotShowNotification); connect(&m_timeTracker, &TimeTrackingWindow::taskMenuChanged, this, &ApplicationCore::slotPopulateTrayIconMenu); // save the configuration (configuration is managed by the application) connect(&m_tasksView, &TasksView::saveConfiguration, this, &ApplicationCore::slotSaveConfiguration); // due to multiple inheritence we can't use the new style connects here connect(&m_tasksView, SIGNAL(emitCommand(CharmCommand*)), &m_timeTracker, SLOT(sendCommand(CharmCommand*))); connect(&m_tasksView, SIGNAL(emitCommandRollback(CharmCommand*)), &m_timeTracker, SLOT(sendCommandRollback(CharmCommand*))); connect(&m_eventView, SIGNAL(emitCommand(CharmCommand*)), &m_timeTracker, SLOT(sendCommand(CharmCommand*))); connect(&m_eventView, SIGNAL(emitCommandRollback(CharmCommand*)), &m_timeTracker, SLOT(sendCommandRollback(CharmCommand*))); // my own signals: connect(this, &ApplicationCore::goToState, this, &ApplicationCore::setState, Qt::QueuedConnection); // system tray icon: m_actionStopAllTasks.setText(tr("Stop Current Task")); m_actionStopAllTasks.setShortcut(Qt::Key_Escape); m_actionStopAllTasks.setShortcutContext(Qt::ApplicationShortcut); mainView().addAction(&m_actionStopAllTasks); // for the shortcut to work connect(&m_actionStopAllTasks, &QAction::triggered, this, &ApplicationCore::slotStopAllTasks); m_systrayContextMenu.addAction(&m_actionStopAllTasks); m_systrayContextMenu.addSeparator(); m_systrayContextMenu.addAction(m_timeTracker.openCharmAction()); m_systrayContextMenu.addAction(&m_actionQuit); m_trayIcon.setContextMenu(&m_systrayContextMenu); m_trayIcon.setToolTip(tr("No active events")); m_trayIcon.setIcon(Data::charmTrayIcon()); m_trayIcon.show(); QApplication::setWindowIcon(Data::charmIcon()); // set up actions: m_actionQuit.setShortcut(Qt::CTRL + Qt::Key_Q); m_actionQuit.setText(tr("Quit")); m_actionQuit.setIcon(Data::quitCharmIcon()); connect(&m_actionQuit, &QAction::triggered, this, &ApplicationCore::slotQuitApplication); m_actionAboutDialog.setText(tr("About Charm")); connect(&m_actionAboutDialog, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotAboutDialog); m_actionPreferences.setText(tr("Preferences")); m_actionPreferences.setIcon(Data::configureIcon()); connect(&m_actionPreferences, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotEditPreferences); m_actionPreferences.setEnabled(true); m_actionImportFromXml.setText(tr("Import Database from Previous Export...")); connect(&m_actionImportFromXml, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotImportFromXml); m_actionExportToXml.setText(tr("Export Database...")); connect(&m_actionExportToXml, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotExportToXml); m_actionSyncTasks.setText(tr("Update Task Definitions...")); //the signature of QAction::triggered does not match slotSyncTasks connect(&m_actionSyncTasks,&QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotSyncTasksVerbose); m_actionImportTasks.setText(tr("Import and Merge Task Definitions...")); connect(&m_actionImportTasks, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotImportTasks); m_actionExportTasks.setText(tr("Export Task Definitions...")); connect(&m_actionExportTasks, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotExportTasks); m_actionCheckForUpdates.setText(tr("Check for Updates...")); #if 0 // TODO this role should be set to have the action in the app menu, but that // leads to duplicated entries, as each of the three main windows adds the action to the menu // and Qt doesn't prevent duplicates (#222) m_actionCheckForUpdates.setMenuRole(QAction::ApplicationSpecificRole); #endif connect(&m_actionCheckForUpdates, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotCheckForUpdatesManual); m_actionEnterVacation.setText(tr("Enter Vacation...")); connect(&m_actionEnterVacation, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotEnterVacation); m_actionActivityReport.setText(tr("Activity Report...")); m_actionActivityReport.setShortcut(Qt::CTRL + Qt::Key_A); connect(&m_actionActivityReport, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotActivityReport); m_actionWeeklyTimesheetReport.setText(tr("Weekly Timesheet...")); m_actionWeeklyTimesheetReport.setShortcut(Qt::CTRL + Qt::Key_R); connect(&m_actionWeeklyTimesheetReport, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotWeeklyTimesheetReport); m_actionMonthlyTimesheetReport.setText(tr("Monthly Timesheet...")); m_actionMonthlyTimesheetReport.setShortcut(Qt::CTRL + Qt::Key_M); connect(&m_actionMonthlyTimesheetReport, &QAction::triggered, &m_timeTracker, &TimeTrackingWindow::slotMonthlyTimesheetReport); // set up idle detection m_idleDetector = IdleDetector::createIdleDetector(this); Q_ASSERT(m_idleDetector); connect(m_idleDetector, SIGNAL(maybeIdle()), SLOT(slotMaybeIdle())); setHttpActionsVisible(Lotsofcake::Configuration().isConfigured()); // add default plugin path for deployment QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + QStringLiteral("/plugins")); if (QCoreApplication::applicationDirPath().endsWith(QLatin1String("MacOS"))) QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + QStringLiteral("/../plugins")); // set up command interface #ifdef CHARM_CI_SUPPORT m_cmdInterface = new CharmCommandInterface(this); #endif // CHARM_CI_SUPPORT // Ladies and gentlemen, please raise upon your seats - // the show is about to begin: emit goToState(StartingUp); }
void ApplicationCore::showInformation(const QString &title, const QString &message) { QMessageBox::information(&mainView(), title, message); }
void ApplicationCore::showCritical(const QString &title, const QString &message) { QMessageBox::critical(&mainView(), title, message); }