1bb02e0acSNicolas Bonnefon /* 2b57881faSNicolas 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 26b57881faSNicolas Bonnefon const int SessionInfo::OPENFILES_VERSION = 1; 27b57881faSNicolas Bonnefon 28bb02e0acSNicolas Bonnefon void SessionInfo::retrieveFromStorage( QSettings& settings ) 29bb02e0acSNicolas Bonnefon { 30bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "SessionInfo::retrieveFromStorage"; 31bb02e0acSNicolas Bonnefon 32b57881faSNicolas Bonnefon /* 33bb02e0acSNicolas Bonnefon geometry_ = settings.value("geometry").toByteArray(); 34bb02e0acSNicolas Bonnefon crawlerState_ = settings.value("crawlerWidget").toByteArray(); 35b57881faSNicolas Bonnefon */ 36b57881faSNicolas Bonnefon if ( settings.contains( "OpenFiles/version" ) ) { 37b57881faSNicolas Bonnefon // Unserialise the "new style" stored history 38b57881faSNicolas Bonnefon settings.beginGroup( "OpenFiles" ); 39b57881faSNicolas Bonnefon if ( settings.value( "version" ) == OPENFILES_VERSION ) { 40b57881faSNicolas Bonnefon int size = settings.beginReadArray( "openFiles" ); 41b57881faSNicolas Bonnefon for (int i = 0; i < size; ++i) { 42b57881faSNicolas Bonnefon settings.setArrayIndex(i); 43b57881faSNicolas Bonnefon std::string file_name = 44b57881faSNicolas Bonnefon settings.value( "fileName" ).toString().toStdString(); 45b57881faSNicolas Bonnefon uint64_t top_line = settings.value( "topLine" ).toInt(); 46*a44d09bcSNicolas Bonnefon std::string view_context = 47*a44d09bcSNicolas Bonnefon settings.value( "viewContext" ).toString().toStdString(); 48*a44d09bcSNicolas Bonnefon openFiles_.push_back( { file_name, top_line, view_context } ); 49b57881faSNicolas Bonnefon } 50b57881faSNicolas Bonnefon settings.endArray(); 51b57881faSNicolas Bonnefon } 52b57881faSNicolas Bonnefon else { 53b57881faSNicolas Bonnefon LOG(logERROR) << "Unknown version of OpenFiles, ignoring it..."; 54b57881faSNicolas Bonnefon } 55b57881faSNicolas Bonnefon settings.endGroup(); 56b57881faSNicolas Bonnefon } 57bb02e0acSNicolas Bonnefon } 58bb02e0acSNicolas Bonnefon 59bb02e0acSNicolas Bonnefon void SessionInfo::saveToStorage( QSettings& settings ) const 60bb02e0acSNicolas Bonnefon { 61bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "SessionInfo::saveToStorage"; 62bb02e0acSNicolas Bonnefon 63b57881faSNicolas Bonnefon /* 64bb02e0acSNicolas Bonnefon settings.setValue( "geometry", geometry_ ); 65bb02e0acSNicolas Bonnefon settings.setValue( "crawlerWidget", crawlerState_ ); 66b57881faSNicolas Bonnefon */ 67b57881faSNicolas Bonnefon settings.beginGroup( "OpenFiles" ); 68b57881faSNicolas Bonnefon settings.setValue( "version", OPENFILES_VERSION ); 69b57881faSNicolas Bonnefon settings.beginWriteArray( "openFiles" ); 70*a44d09bcSNicolas Bonnefon for ( unsigned i = 0; i < openFiles_.size(); ++i ) { 71b57881faSNicolas Bonnefon settings.setArrayIndex( i ); 72b57881faSNicolas Bonnefon const OpenFile* open_file = &(openFiles_.at( i )); 73b57881faSNicolas Bonnefon settings.setValue( "fileName", QString( open_file->fileName.c_str() ) ); 74b57881faSNicolas Bonnefon settings.setValue( "topLine", qint64( open_file->topLine ) ); 75*a44d09bcSNicolas Bonnefon settings.setValue( "viewContext", QString( open_file->viewContext.c_str() ) ); 76b57881faSNicolas Bonnefon } 77b57881faSNicolas Bonnefon settings.endArray(); 78b57881faSNicolas Bonnefon settings.endGroup(); 79bb02e0acSNicolas Bonnefon } 80