SilentEye 0.4.1
|
00001 // This file is part of SilentEye. 00002 // 00003 // SilentEye is free software: you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation, either version 3 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // SilentEye is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with SilentEye. If not, see <http://www.gnu.org/licenses/>. 00015 00016 #include <QApplication> 00017 00018 #include "logger.h" 00019 #include "mainwindow.h" 00020 #include "modulemanager.h" 00021 #include "controller.h" 00022 #include <audio.h> 00023 00024 using namespace SilentEyeFramework; 00025 using namespace SilentEye; 00026 00028 00031 void showMessage(QString msg, Logger& logger) 00032 { 00033 logger.warning(msg); 00034 QMessageBox mb("SilentEye Warning", 00035 msg, QMessageBox::Warning, 0, 0, 0); 00036 mb.exec(); 00037 } 00038 00040 00044 int main(int argc, char *argv[]) 00045 { 00046 QApplication app(argc, argv); 00047 #ifdef STATICPLUGINS 00048 Q_INIT_RESOURCE(silenteye); 00049 #endif 00050 00051 Controller::instance()->appPath = qApp->applicationDirPath()+"/"; 00052 Controller::instance()->config = Config(Controller::instance()->appPath, "silenteye"); 00053 00054 Logger::setFileName(Controller::instance()->appPath + "silenteye.log"); 00055 Logger::setLevel(Controller::instance()->config.get("loglevel")); 00056 00057 ModuleManager::load(); 00058 00059 if (app.argc() <= 1) 00060 { 00061 /* Normal mode */ 00062 if( !Controller::instance()->config.contains("output") || Controller::instance()->config.get("output").trimmed() == "") 00063 // default output is the user home 00064 Controller::instance()->config.set("output", QDir::homePath()+"/"); 00065 00066 Controller::instance()->updateProxySettings(); 00067 00068 MainWindow mainWin; 00069 mainWin.show(); 00070 return app.exec(); 00071 } 00072 else 00073 { 00074 /* Quick mode */ 00075 Logger logger("main"); 00076 for (int i = 0; i < app.argc(); i++) 00077 logger.debug("Parameter " + QString::number(i) + ": " + QString(app.argv()[i])); 00078 00079 QString action(app.argv()[1]); 00080 QString filePath(app.argv()[2]); 00081 00082 if(app.argc() == 2) { 00083 action = "open"; 00084 filePath = app.argv()[1]; 00085 } else if(app.argc() == 3) { 00086 action = app.argv()[1]; 00087 filePath = app.argv()[2]; 00088 } else { 00089 showMessage("Usage: " + QString(app.argv()[0]) 00090 + " <action> [file_path]\n" 00091 + "action: encode/decode\n" 00092 + "file_path: absolute path to media", logger); 00093 return 1; 00094 } 00095 00096 if( !Controller::instance()->config.contains("output") || Controller::instance()->config.get("output").trimmed() == "") 00097 // default output is the current directory 00098 Controller::instance()->config.set("output", QDir::currentPath()); 00099 00100 if (!QFile::exists(filePath)) { 00101 showMessage("Cannot load '" + filePath 00102 + "'\n file: file not found.", logger); 00103 return 2; 00104 } 00105 if(action == "open") { 00106 Controller::instance()->updateProxySettings(); 00107 00108 MainWindow mainWin(filePath); 00109 mainWin.show(); 00110 return app.exec(); 00111 } 00112 00113 // Load Media 00114 QPointer<Media> md; 00115 if (filePath.endsWith(".wav", Qt::CaseInsensitive)) { 00116 00117 try { 00118 md = new Audio(filePath); 00119 } catch (SilentEyeException e) { 00120 showMessage("Cannot load '" + filePath 00121 + "'\n file: unsupported media type. (" 00122 + e.details() + ")", logger); 00123 return 2; 00124 } 00125 } else { 00126 md = new Image(filePath); 00127 if(((Image*)md.data())->isNull()) 00128 { 00129 showMessage("Cannot load '" + filePath 00130 + "'\n file: unsupported media type.", logger); 00131 return 2; 00132 } 00133 } 00134 00135 // create the specified dialog 00136 OptionDialog* dialog = NULL; 00137 if (action == "encode") { 00138 dialog = new EncodeDialog(); 00139 } else if(action == "decode") { 00140 dialog = new DecodeDialog(); 00141 } else { 00142 showMessage("Specified action not recognised: " + action, logger); 00143 return 3; 00144 } 00145 00146 // setup dialog 00147 dialog->setMedia(md); 00148 00149 int return_code = dialog->exec(); 00150 delete dialog; 00151 return return_code; 00152 } 00153 } 00154