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