1bb02e0acSNicolas Bonnefon /* 2*812146a8SNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2013, 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 <QApplication> 21bb02e0acSNicolas Bonnefon 22d96f3f21SNicolas Bonnefon #include <memory> 23d96f3f21SNicolas Bonnefon 24bb02e0acSNicolas Bonnefon #include <boost/program_options.hpp> 25bb02e0acSNicolas Bonnefon namespace po = boost::program_options; 26bb02e0acSNicolas Bonnefon 27bb02e0acSNicolas Bonnefon #include <iostream> 28bb02e0acSNicolas Bonnefon using namespace std; 29bb02e0acSNicolas Bonnefon 30bb02e0acSNicolas Bonnefon #include "persistentinfo.h" 31bb02e0acSNicolas Bonnefon #include "sessioninfo.h" 32bb02e0acSNicolas Bonnefon #include "configuration.h" 33bb02e0acSNicolas Bonnefon #include "filterset.h" 34bb02e0acSNicolas Bonnefon #include "recentfiles.h" 35d96f3f21SNicolas Bonnefon #include "session.h" 36bb02e0acSNicolas Bonnefon #include "mainwindow.h" 37bb02e0acSNicolas Bonnefon #include "savedsearches.h" 38*812146a8SNicolas Bonnefon #include "loadingstatus.h" 39bb02e0acSNicolas Bonnefon #include "log.h" 40bb02e0acSNicolas Bonnefon 41bb02e0acSNicolas Bonnefon static void print_version(); 42bb02e0acSNicolas Bonnefon 43bb02e0acSNicolas Bonnefon int main(int argc, char *argv[]) 44bb02e0acSNicolas Bonnefon { 45bb02e0acSNicolas Bonnefon QApplication app(argc, argv); 46bb02e0acSNicolas Bonnefon 47bb02e0acSNicolas Bonnefon string filename = ""; 48bb02e0acSNicolas Bonnefon 49bb02e0acSNicolas Bonnefon TLogLevel logLevel = logWARNING; 50bb02e0acSNicolas Bonnefon 51bb02e0acSNicolas Bonnefon try { 52bb02e0acSNicolas Bonnefon po::options_description desc("Usage: glogg [options] [file]"); 53bb02e0acSNicolas Bonnefon desc.add_options() 54bb02e0acSNicolas Bonnefon ("help,h", "print out program usage (this message)") 55bb02e0acSNicolas Bonnefon ("version,v", "print glogg's version information") 56bb02e0acSNicolas Bonnefon ("debug,d", "output more debug (include multiple times for more verbosity e.g. -dddd") 57bb02e0acSNicolas Bonnefon ; 58bb02e0acSNicolas Bonnefon po::options_description desc_hidden("Hidden options"); 59bb02e0acSNicolas Bonnefon // For -dd, -ddd... 60bb02e0acSNicolas Bonnefon for ( string s = "dd"; s.length() <= 10; s.append("d") ) 61bb02e0acSNicolas Bonnefon desc_hidden.add_options()(s.c_str(), "debug"); 62bb02e0acSNicolas Bonnefon 63bb02e0acSNicolas Bonnefon desc_hidden.add_options() 64bb02e0acSNicolas Bonnefon ("input-file", po::value<string>(), "input file") 65bb02e0acSNicolas Bonnefon ; 66bb02e0acSNicolas Bonnefon 67bb02e0acSNicolas Bonnefon po::options_description all_options("all options"); 68bb02e0acSNicolas Bonnefon all_options.add(desc).add(desc_hidden); 69bb02e0acSNicolas Bonnefon 70bb02e0acSNicolas Bonnefon po::positional_options_description positional; 71bb02e0acSNicolas Bonnefon positional.add("input-file", 1); 72bb02e0acSNicolas Bonnefon 73bb02e0acSNicolas Bonnefon int command_line_style = (((po::command_line_style::unix_style ^ 74bb02e0acSNicolas Bonnefon po::command_line_style::allow_guessing) | 75bb02e0acSNicolas Bonnefon po::command_line_style::allow_long_disguise) ^ 76bb02e0acSNicolas Bonnefon po::command_line_style::allow_sticky); 77bb02e0acSNicolas Bonnefon 78bb02e0acSNicolas Bonnefon po::variables_map vm; 79bb02e0acSNicolas Bonnefon po::store(po::command_line_parser(argc, argv). 80bb02e0acSNicolas Bonnefon options(all_options). 81bb02e0acSNicolas Bonnefon positional(positional). 82bb02e0acSNicolas Bonnefon style(command_line_style).run(), 83bb02e0acSNicolas Bonnefon vm); 84bb02e0acSNicolas Bonnefon po::notify(vm); 85bb02e0acSNicolas Bonnefon 86bb02e0acSNicolas Bonnefon if ( vm.count("help") ) { 87bb02e0acSNicolas Bonnefon desc.print(cout); 88bb02e0acSNicolas Bonnefon return 0; 89bb02e0acSNicolas Bonnefon } 90bb02e0acSNicolas Bonnefon 91bb02e0acSNicolas Bonnefon if ( vm.count("version") ) { 92bb02e0acSNicolas Bonnefon print_version(); 93bb02e0acSNicolas Bonnefon return 0; 94bb02e0acSNicolas Bonnefon } 95bb02e0acSNicolas Bonnefon 96bb02e0acSNicolas Bonnefon if ( vm.count( "debug" ) ) { 97bb02e0acSNicolas Bonnefon logLevel = logINFO; 98bb02e0acSNicolas Bonnefon } 99bb02e0acSNicolas Bonnefon 100bb02e0acSNicolas Bonnefon for ( string s = "dd"; s.length() <= 10; s.append("d") ) 101bb02e0acSNicolas Bonnefon if ( vm.count( s ) ) 102bb02e0acSNicolas Bonnefon logLevel = (TLogLevel) (logWARNING + s.length()); 103bb02e0acSNicolas Bonnefon 104bb02e0acSNicolas Bonnefon if ( vm.count("input-file") ) 105bb02e0acSNicolas Bonnefon filename = vm["input-file"].as<string>(); 106bb02e0acSNicolas Bonnefon } 107bb02e0acSNicolas Bonnefon catch(exception& e) { 108bb02e0acSNicolas Bonnefon cerr << "Option processing error: " << e.what() << endl; 109bb02e0acSNicolas Bonnefon return 1; 110bb02e0acSNicolas Bonnefon } 111bb02e0acSNicolas Bonnefon catch(...) { 112bb02e0acSNicolas Bonnefon cerr << "Exception of unknown type!\n"; 113bb02e0acSNicolas Bonnefon } 114bb02e0acSNicolas Bonnefon 115bb02e0acSNicolas Bonnefon #if 0 116bb02e0acSNicolas Bonnefon FILE* file = fopen("glogg.log", "w"); 117bb02e0acSNicolas Bonnefon Output2FILE::Stream() = file; 118bb02e0acSNicolas Bonnefon #endif 119bb02e0acSNicolas Bonnefon 120bb02e0acSNicolas Bonnefon FILELog::setReportingLevel( logLevel ); 121bb02e0acSNicolas Bonnefon 122*812146a8SNicolas Bonnefon // Register types for Qt 123*812146a8SNicolas Bonnefon qRegisterMetaType<LoadingStatus>("LoadingStatus"); 124*812146a8SNicolas Bonnefon 125bb02e0acSNicolas Bonnefon // Register the configuration items 126bb02e0acSNicolas Bonnefon GetPersistentInfo().migrateAndInit(); 127bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 12811582726SNicolas Bonnefon std::make_shared<SessionInfo>(), QString( "session" ) ); 129bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 13011582726SNicolas Bonnefon std::make_shared<Configuration>(), QString( "settings" ) ); 131bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 13211582726SNicolas Bonnefon std::make_shared<FilterSet>(), QString( "filterSet" ) ); 133bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 13411582726SNicolas Bonnefon std::make_shared<SavedSearches>(), QString( "savedSearches" ) ); 135bb02e0acSNicolas Bonnefon GetPersistentInfo().registerPersistable( 13611582726SNicolas Bonnefon std::make_shared<RecentFiles>(), QString( "recentFiles" ) ); 137bb02e0acSNicolas Bonnefon 138bb02e0acSNicolas Bonnefon // FIXME: should be replaced by a two staged init of MainWindow 139bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( QString( "settings" ) ); 140bb02e0acSNicolas Bonnefon 141d96f3f21SNicolas Bonnefon std::unique_ptr<Session> session( new Session() ); 1420f9fd9edSNicolas Bonnefon MainWindow mw( std::move( session ) ); 143bb02e0acSNicolas Bonnefon 144bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "MainWindow created."; 1450f9fd9edSNicolas Bonnefon mw.show(); 1460f9fd9edSNicolas Bonnefon mw.reloadSession(); 1470f9fd9edSNicolas Bonnefon mw.loadInitialFile( QString::fromStdString( filename ) ); 148bb02e0acSNicolas Bonnefon return app.exec(); 149bb02e0acSNicolas Bonnefon } 150bb02e0acSNicolas Bonnefon 151bb02e0acSNicolas Bonnefon static void print_version() 152bb02e0acSNicolas Bonnefon { 153bb02e0acSNicolas Bonnefon cout << "glogg " GLOGG_VERSION "\n"; 154bb02e0acSNicolas Bonnefon #ifdef GLOGG_COMMIT 155bb02e0acSNicolas Bonnefon cout << "Built " GLOGG_DATE " from " GLOGG_COMMIT "\n"; 156bb02e0acSNicolas Bonnefon #endif 157d96f3f21SNicolas Bonnefon cout << "Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Bonnefon and other contributors\n"; 158bb02e0acSNicolas Bonnefon cout << "This is free software. You may redistribute copies of it under the terms of\n"; 159bb02e0acSNicolas Bonnefon cout << "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"; 160bb02e0acSNicolas Bonnefon cout << "There is NO WARRANTY, to the extent permitted by law.\n"; 161bb02e0acSNicolas Bonnefon } 162