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