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