| 1 |
/* |
| 2 |
* main.cpp |
| 3 |
* |
| 4 |
* Created on: 6 Sep 2015 |
| 5 |
* Author: jeremy |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "../config.h" |
| 9 |
#include "exadrumsConfig.h" |
| 10 |
#include "Util/Util.h" |
| 11 |
#include "Util/ErrorHandler.h" |
| 12 |
#include "Controllers/MainController.h" |
| 13 |
|
| 14 |
#include <gtkmm/window.h> |
| 15 |
#include <gtkmm/application.h> |
| 16 |
#include <gtkmm/builder.h> |
| 17 |
#include <gtkmm/aboutdialog.h> |
| 18 |
#include <gtkmm/button.h> |
| 19 |
|
| 20 |
#include <string> |
| 21 |
|
| 22 |
using namespace eXaDrums; |
| 23 |
using namespace Util; |
| 24 |
using namespace Errors; |
| 25 |
|
| 26 |
int main(int argc, char** argv) |
| 27 |
{ |
| 28 |
|
| 29 |
Config config; |
| 30 |
|
| 31 |
if(!IsInstalledForUser()) |
| 32 |
{ |
| 33 |
InstallForUser(); |
| 34 |
} |
| 35 |
|
| 36 |
for(;;) |
| 37 |
{ |
| 38 |
|
| 39 |
// Init main controller |
| 40 |
Controllers::MainController controller; |
| 41 |
|
| 42 |
auto app = Gtk::Application::create(argc, argv, "org.eXaDrums", Gio::APPLICATION_HANDLES_COMMAND_LINE); |
| 43 |
app->signal_command_line().connect([&](const Glib::RefPtr<Gio::ApplicationCommandLine>& cmd){ return config.CommandLineParser(cmd, app); }, false); |
| 44 |
|
| 45 |
Gtk::Window* mainWindow = nullptr; |
| 46 |
auto quit = [&] { mainWindow->hide(); }; |
| 47 |
|
| 48 |
auto toggle_fullscreen = [&](Gtk::Button* fs_button) |
| 49 |
{ |
| 50 |
if(!is_fullscreen) |
| 51 |
{ |
| 52 |
mainWindow->fullscreen(); |
| 53 |
fs_button->set_property("label", Gtk::StockID("gtk-leave-fullscreen")); |
| 54 |
is_fullscreen = true; |
| 55 |
} |
| 56 |
else |
| 57 |
{ |
| 58 |
mainWindow->unfullscreen(); |
| 59 |
fs_button->set_property("label", Gtk::StockID("gtk-fullscreen")); |
| 60 |
is_fullscreen = false; |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
// Create main controller and Gui only if the app has been activated |
| 65 |
app->signal_activate().connect([&] |
| 66 |
{ |
| 67 |
|
| 68 |
Glib::RefPtr<Gtk::Builder> builder; |
| 69 |
try |
| 70 |
{ |
| 71 |
builder = Gtk::Builder::create_from_file(UiPath()); |
| 72 |
} |
| 73 |
catch(...) |
| 74 |
{ |
| 75 |
errorDialog("Could not find UI file (" + UiPath().string() + ").", error_type_error); |
| 76 |
return; // Exit properly if UI file can't be loaded. |
| 77 |
} |
| 78 |
|
| 79 |
try |
| 80 |
{ |
| 81 |
controller.Create(builder, UserDataPath(), quit, IsRoot()); |
| 82 |
} |
| 83 |
catch(...) |
| 84 |
{ |
| 85 |
return; // Exit properly if controller can't be created. |
| 86 |
} |
| 87 |
|
| 88 |
// Get about dialog and set software version |
| 89 |
GetWidget<Gtk::AboutDialog>(builder, "eXaDrumsAboutDialog")->set_version(PACKAGE_VERSION); |
| 90 |
|
| 91 |
// Get main window |
| 92 |
builder->get_widget("MainWindow", mainWindow); |
| 93 |
|
| 94 |
// Handle quit button signal |
| 95 |
GetWidget<Gtk::Button>(builder, "QuitButton")->signal_clicked().connect(quit); |
| 96 |
const auto fsButton = GetWidget<Gtk::Button>(builder, "FullScreenButton"); |
| 97 |
fsButton->signal_clicked().connect([&, fsButton]{ toggle_fullscreen(fsButton); }); |
| 98 |
|
| 99 |
if(is_fullscreen) |
| 100 |
{ |
| 101 |
is_fullscreen = false; |
| 102 |
toggle_fullscreen(fsButton); |
| 103 |
} |
| 104 |
|
| 105 |
app->add_window(*mainWindow); |
| 106 |
mainWindow->show(); |
| 107 |
|
| 108 |
}, false); |
| 109 |
|
| 110 |
|
| 111 |
// Run application |
| 112 |
const auto ret = app->run(); |
| 113 |
|
| 114 |
if(!controller.ReebootRequired()) |
| 115 |
{ |
| 116 |
return ret; |
| 117 |
} |
| 118 |
} |
| 119 |
} |