1bb02e0acSNicolas Bonnefon /* 2*b57881faSNicolas Bonnefon * Copyright (C) 2011, 2014 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon #include "sessioninfo.h" 21bb02e0acSNicolas Bonnefon 22bb02e0acSNicolas Bonnefon #include <QSettings> 23bb02e0acSNicolas Bonnefon 24bb02e0acSNicolas Bonnefon #include "log.h" 25bb02e0acSNicolas Bonnefon 26*b57881faSNicolas Bonnefon const int SessionInfo::OPENFILES_VERSION = 1; 27*b57881faSNicolas Bonnefon 28bb02e0acSNicolas Bonnefon void SessionInfo::retrieveFromStorage( QSettings& settings ) 29bb02e0acSNicolas Bonnefon { 30bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "SessionInfo::retrieveFromStorage"; 31bb02e0acSNicolas Bonnefon 32*b57881faSNicolas Bonnefon /* 33bb02e0acSNicolas Bonnefon geometry_ = settings.value("geometry").toByteArray(); 34bb02e0acSNicolas Bonnefon crawlerState_ = settings.value("crawlerWidget").toByteArray(); 35*b57881faSNicolas Bonnefon */ 36*b57881faSNicolas Bonnefon if ( settings.contains( "OpenFiles/version" ) ) { 37*b57881faSNicolas Bonnefon // Unserialise the "new style" stored history 38*b57881faSNicolas Bonnefon settings.beginGroup( "OpenFiles" ); 39*b57881faSNicolas Bonnefon if ( settings.value( "version" ) == OPENFILES_VERSION ) { 40*b57881faSNicolas Bonnefon int size = settings.beginReadArray( "openFiles" ); 41*b57881faSNicolas Bonnefon for (int i = 0; i < size; ++i) { 42*b57881faSNicolas Bonnefon settings.setArrayIndex(i); 43*b57881faSNicolas Bonnefon std::string file_name = 44*b57881faSNicolas Bonnefon settings.value( "fileName" ).toString().toStdString(); 45*b57881faSNicolas Bonnefon uint64_t top_line = settings.value( "topLine" ).toInt(); 46*b57881faSNicolas Bonnefon openFiles_.push_back( { file_name, top_line } ); 47*b57881faSNicolas Bonnefon } 48*b57881faSNicolas Bonnefon settings.endArray(); 49*b57881faSNicolas Bonnefon } 50*b57881faSNicolas Bonnefon else { 51*b57881faSNicolas Bonnefon LOG(logERROR) << "Unknown version of OpenFiles, ignoring it..."; 52*b57881faSNicolas Bonnefon } 53*b57881faSNicolas Bonnefon settings.endGroup(); 54*b57881faSNicolas Bonnefon } 55bb02e0acSNicolas Bonnefon } 56bb02e0acSNicolas Bonnefon 57bb02e0acSNicolas Bonnefon void SessionInfo::saveToStorage( QSettings& settings ) const 58bb02e0acSNicolas Bonnefon { 59bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "SessionInfo::saveToStorage"; 60bb02e0acSNicolas Bonnefon 61*b57881faSNicolas Bonnefon /* 62bb02e0acSNicolas Bonnefon settings.setValue( "geometry", geometry_ ); 63bb02e0acSNicolas Bonnefon settings.setValue( "crawlerWidget", crawlerState_ ); 64*b57881faSNicolas Bonnefon */ 65*b57881faSNicolas Bonnefon settings.beginGroup( "OpenFiles" ); 66*b57881faSNicolas Bonnefon settings.setValue( "version", OPENFILES_VERSION ); 67*b57881faSNicolas Bonnefon settings.beginWriteArray( "openFiles" ); 68*b57881faSNicolas Bonnefon for ( int i = 0; i < openFiles_.size(); ++i ) { 69*b57881faSNicolas Bonnefon settings.setArrayIndex( i ); 70*b57881faSNicolas Bonnefon const OpenFile* open_file = &(openFiles_.at( i )); 71*b57881faSNicolas Bonnefon settings.setValue( "fileName", QString( open_file->fileName.c_str() ) ); 72*b57881faSNicolas Bonnefon settings.setValue( "topLine", qint64( open_file->topLine ) ); 73*b57881faSNicolas Bonnefon } 74*b57881faSNicolas Bonnefon settings.endArray(); 75*b57881faSNicolas Bonnefon settings.endGroup(); 76bb02e0acSNicolas Bonnefon } 77