void QSpotifySession::initiateQuit() { qDebug() << "QSpotifySession::initiateQuit"; stop(); m_audioThread->quit(); m_audioThread->wait(); if(!m_isLoggedIn) { this->deleteLater(); return; } QEventLoop evLoop; evLoop.connect(this, SIGNAL(readyToQuit()), SLOT(quit())); m_aboutToQuit = true; QSpotifyCacheManager::instance().clearTables(); logout(true); evLoop.exec(); this->deleteLater(); }
void QSpotifySession::onLoggedOut() { qDebug() << "QSpotifySession::onLoggedOut"; if (!m_explicitLogout) return; if(m_aboutToQuit) { m_aboutToQuit = false; emit readyToQuit(); return; } m_explicitLogout = false; m_isLoggedIn = false; m_pending_connectionRequest = false; emit pendingConnectionRequestChanged(); emit isLoggedInChanged(); }
void Controller::stateChanged( State previous, State next ) { Q_UNUSED( previous ); switch( next ) { case Connected: { // yes, it is that simple: TaskList tasks = m_storage->getAllTasks(); // tell the view about the existing tasks; if ( ! Task::checkForUniqueTaskIds( tasks ) ) { throw CharmException( tr( "The Charm database is corrupted, it contains duplicate task ids. " "Please have it looked after by a professional." ) ); } if ( ! Task::checkForTreeness( tasks ) ) { throw CharmException( tr( "The Charm database is corrupted, the tasks do not form a tree. " "Please have it looked after by a professional." ) ); } emit definedTasks( tasks ); EventList events = m_storage->getAllEvents(); emit allEvents( events ); } break; case Disconnecting: { emit readyToQuit(); if ( m_storage ) { // this will still leave Qt complaining about a repeated connection // qDebug() << "Application::enterConnectingState: closing existing storage interface"; m_storage->disconnect(); delete m_storage; m_storage = nullptr; } } break; default: break; }; if ( m_storage ) { emit currentBackendStatus( m_storage->description() ); m_storage->stateChanged( previous ); } }
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 ) ) ); }