Changeset 128 for smplayer/trunk/src/smplayer.cpp
- Timestamp:
- Mar 29, 2012, 4:53:15 PM (13 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 127
- Property svn:mergeinfo changed
-
smplayer/trunk/src/smplayer.cpp
r124 r128 26 26 #include "version.h" 27 27 #include "config.h" 28 #include "myclient.h"29 28 #include "clhelp.h" 29 #include "myapplication.h" 30 30 31 31 #include <QDir> 32 #include <QApplication>33 32 #include <QUrl> 34 33 #include <QTime> 35 34 #include <stdio.h> 36 35 … … 42 41 #endif 43 42 44 45 43 using namespace Global; 44 45 BaseGui * SMPlayer::main_window = 0; 46 46 47 47 SMPlayer::SMPlayer(const QString & config_path, QObject * parent ) 48 48 : QObject(parent) 49 49 { 50 main_window = 0; 50 #ifdef LOG_SMPLAYER 51 qInstallMsgHandler( SMPlayer::myMessageOutput ); 52 allow_to_send_log_to_gui = true; 53 #endif 54 51 55 gui_to_use = "DefaultGui"; 52 56 53 57 close_at_end = -1; // Not set 54 58 start_in_fullscreen = -1; // Not set 55 use_control_server = true;56 59 57 60 move_gui = false; 58 61 resize_gui = false; 59 62 60 63 Paths::setAppPath( qApp->applicationDirPath() ); 61 64 62 65 #ifndef PORTABLE_APP … … 71 74 72 75 SMPlayer::~SMPlayer() { 73 if (main_window != 0) delete main_window; 76 if (main_window != 0) { 77 deleteGUI(); 78 } 74 79 global_end(); 80 81 #ifdef LOG_SMPLAYER 82 if (output_log.isOpen()) output_log.close(); 83 #endif 75 84 } 76 85 … … 81 90 qDebug("SMPlayer::gui: changed working directory to app path"); 82 91 qDebug("SMPlayer::gui: current directory: %s", QDir::currentPath().toUtf8().data()); 83 84 if (gui_to_use.toLower() == "minigui") 85 main_window = new MiniGui(use_control_server, 0); 86 else 87 if (gui_to_use.toLower() == "mpcgui") 88 main_window = new MpcGui(use_control_server, 0); 89 else 90 main_window = new DefaultGui(use_control_server, 0); 92 93 main_window = createGUI(gui_to_use); 91 94 92 95 if (move_gui) { … … 98 101 main_window->resize(gui_size); 99 102 } 100 101 main_window->setForceCloseOnFinish(close_at_end);102 main_window->setForceStartInFullscreen(start_in_fullscreen);103 103 } 104 104 105 105 return main_window; 106 106 } 107 108 BaseGui * SMPlayer::createGUI(QString gui_name) { 109 BaseGui * gui = 0; 110 111 if (gui_name.toLower() == "minigui") 112 gui = new MiniGui(0); 113 else 114 if (gui_name.toLower() == "mpcgui") 115 gui = new MpcGui(0); 116 else 117 gui = new DefaultGui(0); 118 119 gui->setForceCloseOnFinish(close_at_end); 120 gui->setForceStartInFullscreen(start_in_fullscreen); 121 connect(gui, SIGNAL(quitSolicited()), qApp, SLOT(quit())); 122 123 #ifdef GUI_CHANGE_ON_RUNTIME 124 connect(gui, SIGNAL(guiChanged(QString)), this, SLOT(changeGUI(QString))); 125 #endif 126 127 #if SINGLE_INSTANCE 128 MyApplication * app = MyApplication::instance(); 129 connect(app, SIGNAL(messageReceived(const QString&)), 130 gui, SLOT(handleMessageFromOtherInstances(const QString&))); 131 app->setActivationWindow(gui); 132 #endif 133 134 return gui; 135 } 136 137 void SMPlayer::deleteGUI() { 138 #ifdef LOG_SMPLAYER 139 allow_to_send_log_to_gui = false; 140 #endif 141 142 delete main_window; 143 main_window = 0; 144 145 #ifdef LOG_SMPLAYER 146 allow_to_send_log_to_gui = true; 147 #endif 148 } 149 150 #ifdef GUI_CHANGE_ON_RUNTIME 151 void SMPlayer::changeGUI(QString new_gui) { 152 qDebug("SMPlayer::changeGUI: '%s'", new_gui.toLatin1().constData()); 153 154 deleteGUI(); 155 156 main_window = createGUI(new_gui); 157 158 main_window->show(); 159 } 160 #endif 107 161 108 162 SMPlayer::ExitCode SMPlayer::processArgs(QStringList args) { … … 222 276 } 223 277 else 224 if (argument == "-disable-server") {225 use_control_server = false;226 }227 else228 278 if (argument == "-add-to-playlist") { 229 279 add_to_playlist = true; … … 266 316 } 267 317 268 318 #ifdef SINGLE_INSTANCE 269 319 if (pref->use_single_instance) { 270 320 // Single instance 271 int port = pref->connection_port; 272 if (pref->use_autoport) port = pref->autoport; 273 274 MyClient *c = new MyClient(port); 275 //c->setTimeOut(1000); 276 qDebug("SMPlayer::processArgs: trying to connect to port %d", port); 277 278 if (c->openConnection()) { 279 qDebug("SMPlayer::processArgs: found another instance"); 321 MyApplication * a = MyApplication::instance(); 322 if (a->isRunning()) { 323 a->sendMessage("Hello"); 280 324 281 325 if (!action.isEmpty()) { 282 if (c->sendAction(action)) { 283 qDebug("SMPlayer::processArgs: action passed successfully to the running instance"); 284 } else { 285 printf("Error: action couldn't be passed to the running instance"); 286 return NoAction; 287 } 326 a->sendMessage("action " + action); 288 327 } 289 328 else { 290 329 if (!subtitle_file.isEmpty()) { 291 if (c->sendSubtitleFile(subtitle_file)) { 292 qDebug("SMPlayer::processArgs: subtitle file sent successfully to the running instance"); 293 } else { 294 qDebug("SMPlayer::processArgs: subtitle file couldn't be sent to another instance"); 295 } 330 a->sendMessage("load_sub " + subtitle_file); 296 331 } 297 332 298 333 if (!files_to_play.isEmpty()) { 299 if (c->sendFiles(files_to_play, add_to_playlist)) { 300 qDebug("SMPlayer::processArgs: files sent successfully to the running instance"); 301 qDebug("SMPlayer::processArgs: exiting."); 302 } else { 303 qDebug("SMPlayer::processArgs: files couldn't be sent to another instance"); 304 } 334 /* a->sendMessage("open_file " + files_to_play[0]); */ 335 QString command = "open_files"; 336 if (add_to_playlist) command = "add_to_playlist"; 337 a->sendMessage(command +" "+ files_to_play.join(" <<sep>> ")); 305 338 } 306 339 } 307 c->closeConnection(); 340 308 341 return NoError; 309 } else { 310 if (!action.isEmpty()) { 311 printf("Error: no running instance found\r\n"); 312 return NoRunningInstance; 313 } 314 } 315 } 342 } 343 } 344 #endif 316 345 317 346 if (!pref->default_font.isEmpty()) { … … 410 439 qDebug(" * current path: '%s'", QDir::currentPath().toUtf8().data()); 411 440 } 441 442 #ifdef LOG_SMPLAYER 443 QFile SMPlayer::output_log; 444 bool SMPlayer::allow_to_send_log_to_gui = false; 445 446 void SMPlayer::myMessageOutput( QtMsgType type, const char *msg ) { 447 static QStringList saved_lines; 448 static QString orig_line; 449 static QString line2; 450 static QRegExp rx_log; 451 452 if (pref) { 453 if (!pref->log_smplayer) return; 454 rx_log.setPattern(pref->log_filter); 455 } else { 456 rx_log.setPattern(".*"); 457 } 458 459 line2.clear(); 460 461 orig_line = QString::fromUtf8(msg); 462 463 switch ( type ) { 464 case QtDebugMsg: 465 if (rx_log.indexIn(orig_line) > -1) { 466 #ifndef NO_DEBUG_ON_CONSOLE 467 fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() ); 468 #endif 469 line2 = orig_line; 470 } 471 break; 472 case QtWarningMsg: 473 #ifndef NO_DEBUG_ON_CONSOLE 474 fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() ); 475 #endif 476 line2 = "WARNING: " + orig_line; 477 break; 478 case QtFatalMsg: 479 #ifndef NO_DEBUG_ON_CONSOLE 480 fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() ); 481 #endif 482 line2 = "FATAL: " + orig_line; 483 abort(); // deliberately core dump 484 case QtCriticalMsg: 485 #ifndef NO_DEBUG_ON_CONSOLE 486 fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() ); 487 #endif 488 line2 = "CRITICAL: " + orig_line; 489 break; 490 } 491 492 if (line2.isEmpty()) return; 493 494 line2 = "["+ QTime::currentTime().toString("hh:mm:ss:zzz") +"] "+ line2; 495 496 if (allow_to_send_log_to_gui && main_window) { 497 if (!saved_lines.isEmpty()) { 498 // Send saved lines first 499 for (int n=0; n < saved_lines.count(); n++) { 500 main_window->recordSmplayerLog(saved_lines[n]); 501 } 502 saved_lines.clear(); 503 } 504 main_window->recordSmplayerLog(line2); 505 } else { 506 // GUI is not created yet, save lines for later 507 saved_lines.append(line2); 508 /* printf("SMPlayer::myMessageOutput: no gui\n"); */ 509 } 510 511 if (pref) { 512 if (pref->save_smplayer_log) { 513 // Save log to file 514 if (!output_log.isOpen()) { 515 // FIXME: the config path may not be initialized if USE_LOCKS is not defined 516 output_log.setFileName( Paths::configPath() + "/smplayer_log.txt" ); 517 output_log.open(QIODevice::WriteOnly); 518 } 519 if (output_log.isOpen()) { 520 QString l = line2 + "\r\n"; 521 output_log.write(l.toUtf8().constData()); 522 output_log.flush(); 523 } 524 } 525 } 526 } 527 #endif 528 529 /* 530 void myMessageOutput( QtMsgType type, const char *msg ) { 531 static QString orig_line; 532 orig_line = QString::fromUtf8(msg); 533 534 switch ( type ) { 535 case QtDebugMsg: 536 #ifndef NO_DEBUG_ON_CONSOLE 537 fprintf( stderr, "Debug: %s\n", orig_line.toLocal8Bit().data() ); 538 #endif 539 break; 540 541 case QtWarningMsg: 542 #ifndef NO_DEBUG_ON_CONSOLE 543 fprintf( stderr, "Warning: %s\n", orig_line.toLocal8Bit().data() ); 544 #endif 545 break; 546 547 case QtCriticalMsg: 548 #ifndef NO_DEBUG_ON_CONSOLE 549 fprintf( stderr, "Critical: %s\n", orig_line.toLocal8Bit().data() ); 550 #endif 551 break; 552 553 case QtFatalMsg: 554 #ifndef NO_DEBUG_ON_CONSOLE 555 fprintf( stderr, "Fatal: %s\n", orig_line.toLocal8Bit().data() ); 556 #endif 557 abort(); // deliberately core dump 558 } 559 } 560 */ 561 562 #include "moc_smplayer.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.