xref: /glogg/src/session.cpp (revision 039481acd3250c79a914161903e50a979998e1cb)
1 /*
2  * Copyright (C) 2013 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 "session.h"
21 
22 #include <QFileInfo>
23 
24 #include "viewinterface.h"
25 #include "data/logdata.h"
26 #include "data/logfiltereddata.h"
27 
28 Session::Session()
29 {
30 }
31 
32 Session::~Session()
33 {
34     // FIXME Clean up all the data objects...
35 }
36 
37 ViewInterface* Session::open( const std::string& file_name,
38         std::function<ViewInterface*()> view_factory )
39 {
40     ViewInterface* view = nullptr;
41 
42     QFileInfo fileInfo( file_name.c_str() );
43     if ( fileInfo.isReadable() )
44     {
45         // Create the data objects
46         logData_          = std::shared_ptr<LogData>( new LogData() );
47         logFilteredData_  =
48             std::shared_ptr<LogFilteredData>( logData_->getNewFilteredData() );
49 
50         view = view_factory();
51         view->setData( logData_, logFilteredData_ );
52 
53         // Start loading the file
54         logData_->attachFile( QString( file_name.c_str() ) );
55     }
56     else {
57         // throw
58     }
59 
60     return view;
61 }
62 /*
63 void CrawlerWidget::stopLoading()
64 {
65     logFilteredData_->interruptSearch();
66     logData_->interruptLoading();
67 }
68 
69 void CrawlerWidget::getFileInfo( qint64* fileSize, int* fileNbLine,
70        QDateTime* lastModified ) const
71 {
72     *fileSize = logData_->getFileSize();
73     *fileNbLine = logData_->getNbLine();
74     *lastModified = logData_->getLastModifiedDate();
75 }
76 */
77