xref: /glogg/src/sessioninfo.cpp (revision b76966a660b57dd0cbec7739fa98087bc18b357f)
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 
retrieveFromStorage(QSettings & settings)28bb02e0acSNicolas Bonnefon void SessionInfo::retrieveFromStorage( QSettings& settings )
29bb02e0acSNicolas Bonnefon {
30bb02e0acSNicolas Bonnefon     LOG(logDEBUG) << "SessionInfo::retrieveFromStorage";
31bb02e0acSNicolas Bonnefon 
32bb02e0acSNicolas Bonnefon     geometry_     = settings.value("geometry").toByteArray();
33*b76966a6SNicolas Bonnefon 
34b57881faSNicolas Bonnefon     if ( settings.contains( "OpenFiles/version" ) ) {
35*b76966a6SNicolas Bonnefon         openFiles_.clear();
36b57881faSNicolas Bonnefon         // Unserialise the "new style" stored history
37b57881faSNicolas Bonnefon         settings.beginGroup( "OpenFiles" );
38b57881faSNicolas Bonnefon         if ( settings.value( "version" ) == OPENFILES_VERSION ) {
39b57881faSNicolas Bonnefon             int size = settings.beginReadArray( "openFiles" );
40*b76966a6SNicolas Bonnefon             LOG(logDEBUG) << "SessionInfo: " << size << " files.";
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();
46a44d09bcSNicolas Bonnefon                 std::string view_context =
47a44d09bcSNicolas Bonnefon                     settings.value( "viewContext" ).toString().toStdString();
48a44d09bcSNicolas 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 
saveToStorage(QSettings & settings) const59bb02e0acSNicolas Bonnefon void SessionInfo::saveToStorage( QSettings& settings ) const
60bb02e0acSNicolas Bonnefon {
61bb02e0acSNicolas Bonnefon     LOG(logDEBUG) << "SessionInfo::saveToStorage";
62bb02e0acSNicolas Bonnefon 
63bb02e0acSNicolas Bonnefon     settings.setValue( "geometry", geometry_ );
64b57881faSNicolas Bonnefon     settings.beginGroup( "OpenFiles" );
65b57881faSNicolas Bonnefon     settings.setValue( "version", OPENFILES_VERSION );
66b57881faSNicolas Bonnefon     settings.beginWriteArray( "openFiles" );
67a44d09bcSNicolas Bonnefon     for ( unsigned i = 0; i < openFiles_.size(); ++i ) {
68b57881faSNicolas Bonnefon         settings.setArrayIndex( i );
69b57881faSNicolas Bonnefon         const OpenFile* open_file = &(openFiles_.at( i ));
70b57881faSNicolas Bonnefon         settings.setValue( "fileName", QString( open_file->fileName.c_str() ) );
71b57881faSNicolas Bonnefon         settings.setValue( "topLine", qint64( open_file->topLine ) );
72a44d09bcSNicolas Bonnefon         settings.setValue( "viewContext", QString( open_file->viewContext.c_str() ) );
73b57881faSNicolas Bonnefon     }
74b57881faSNicolas Bonnefon     settings.endArray();
75b57881faSNicolas Bonnefon     settings.endGroup();
76bb02e0acSNicolas Bonnefon }
77