MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / onlySingleInstance

Function onlySingleInstance

src/Gui/Application.cpp:2510–2540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2508namespace
2509{
2510bool 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
2542void setAppNameAndIcon()
2543{

Callers 1

runApplicationMethod · 0.85

Calls 9

isRelativeMethod · 0.80
ConfigClass · 0.50
findMethod · 0.45
endMethod · 0.45
isRunningMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45
prependMethod · 0.45
sendMessageMethod · 0.45

Tested by

no test coverage detected