| 2508 | namespace |
| 2509 | { |
| 2510 | bool onlySingleInstance(GUISingleApplication& mainApp) |
| 2511 | { |
| 2512 | const std::map<std::string, std::string>& cfg = App::Application::Config(); |
| 2513 | auto it = cfg.find("SingleInstance"); |
| 2514 | if (it != cfg.end() && mainApp.isRunning()) { |
| 2515 | // send the file names to be opened to the server application so that this |
| 2516 | // opens them |
| 2517 | QDir cwd = QDir::current(); |
| 2518 | std::list<std::string> files = App::Application::getCmdLineFiles(); |
| 2519 | for (const auto& file : files) { |
| 2520 | QString fn = QString::fromUtf8(file.c_str(), static_cast<int>(file.size())); |
| 2521 | QFileInfo fi(fn); |
| 2522 | // if path name is relative make it absolute because the running instance |
| 2523 | // cannot determine the full path when trying to load the file |
| 2524 | if (fi.isRelative()) { |
| 2525 | fn = cwd.absoluteFilePath(fn); |
| 2526 | fn = QDir::cleanPath(fn); |
| 2527 | } |
| 2528 | |
| 2529 | fn.prepend(QLatin1String("OpenFile:")); |
| 2530 | if (!mainApp.sendMessage(fn)) { |
| 2531 | qWarning("Failed to send OpenFile message to server"); |
| 2532 | break; |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | return true; |
| 2537 | } |
| 2538 | |
| 2539 | return false; |
| 2540 | } |
| 2541 | |
| 2542 | void setAppNameAndIcon() |
| 2543 | { |
no test coverage detected