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