Session * SessionManager::saveSessionAs( const QString & name ) { // TODO: // Maybe use a different data structure for Session instead of QSettings? // A new class that would allow closing without saving would be nice. if (mSession) { delete mSession; mSession = 0; } QDir dir = sessionsDir(); if (dir.path().isEmpty()) { emit switchSessionRequest(0); return 0; } QString sessionFile = dir.filePath(name + ".yaml"); mSession = new Session( sessionFile, name, Settings::serializationFormat() ); emit saveSessionRequest(mSession); mSession->sync(); saveLastSession( dir, sessionFile ); emit currentSessionNameChanged(); return mSession; }
void SessionManager::newSession() { closeSession(); QDir dir = sessionsDir(); if (!dir.path().isEmpty()) saveLastSession( dir, QString() ); emit switchSessionRequest(0); }
void SessionManager::removeSession( const QString & name ) { QDir dir = sessionsDir(); if (dir.path().isEmpty()) return; if (mCurrentSession && mCurrentSession->name() == name) { if (!closeSession()) return; saveLastSession(dir, QString()); emit switchSessionRequest(0); } if (!QFile::remove(dir.filePath(name + ".yaml"))) qWarning("Could not remove a session file!"); }
Session *SessionManager::openSession( const QString & name ) { // NOTE: This will create a session if it doesn't exists closeSession(); QDir dir = sessionsDir(); if (dir.path().isEmpty()) return 0; QString sessionFile = dir.filePath(name + ".yaml"); mSession = new Session( sessionFile, name, Settings::serializationFormat() ); saveLastSession( dir, sessionFile ); emit switchSessionRequest(mSession); return mSession; }