-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
106 lines (104 loc) · 4.2 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* main.cpp
* Copyright (C) 2012-2019 Vitaly Tonkacheyev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "tools/core.h"
#include "gui/sliderwindow.h"
#include "gui/trayicon.h"
#ifndef IS_GTK_2
#include "gtkmm/application.h"
#else
#include "gtkmm/main.h"
#endif
#include "gtkmm/builder.h"
#include "glibmm.h"
#include "libintl.h"
#define _(String) gettext(String)
#define N_(String) gettext_noop (String)
#define PACKAGE "alsavolume"
#define CODEC "UTF-8"
int main (int argc, char *argv[])
{
bindtextdomain(PACKAGE, Tools::getDirPath("locale").c_str());
bind_textdomain_codeset(PACKAGE, CODEC);
textdomain(PACKAGE);
#ifndef IS_GTK_2
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.alsavolume");
Glib::ustring slider_ui_ = Tools::getResPath("gladefiles/SliderFrame.glade");
Glib::ustring settings_ui_ = Tools::getResPath("gladefiles/SettingsFrame.glade");
#else
Gtk::Main app(argc, argv);
Glib::ustring slider_ui_ = Tools::getResPath("gladefiles/SliderFrame_2.glade");
Glib::ustring settings_ui_ = Tools::getResPath("gladefiles/SettingsFrame_2.glade");
#endif
if (slider_ui_.empty()) {
std::cerr << "No SliderFrame.glade file found" << std::endl;
return 1;
}
if (settings_ui_.empty()) {
std::cerr << "No SettingsFrame.glade file found" << std::endl;
return 1;
}
Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
try {
refBuilder->add_from_file(slider_ui_);
refBuilder->add_from_file(settings_ui_);
}
catch(const Gtk::BuilderError& ex) {
std::cerr << "BuilderError::main.cpp::62 " << ex.what() << std::endl;
return 1;
}
catch(const Glib::MarkupError& ex) {
std::cerr << "MarkupError::main.cpp::62 " << ex.what() << std::endl;
return 1;
}
catch(const Glib::FileError& ex) {
std::cerr << "FileError::main.cpp::62 " << ex.what() << std::endl;
return 1;
}
Core::Ptr core(new Core(refBuilder));
#ifndef IS_GTK_2
app->hold();
#endif
SliderWindow *sliderWindow = nullptr;
refBuilder->get_widget_derived("volumeFrame", sliderWindow);
TrayIcon::Ptr trayIcon(new TrayIcon(core->getVolumeValue(),
core->getSoundCardName(),
core->getActiveMixer(),
core->getMuted()));
if (trayIcon && sliderWindow) {
sliderWindow->setVolumeValue(core->getVolumeValue());
core->signal_value_changed().connect(sigc::mem_fun(*trayIcon, &TrayIcon::on_signal_volume_changed));
core->signal_mixer_muted().connect(sigc::mem_fun(*trayIcon, &TrayIcon::setMuted));
core->signal_volume_changed().connect(sigc::mem_fun(*sliderWindow, &SliderWindow::setVolumeValue));
sliderWindow->signal_volume_changed().connect(sigc::mem_fun(*core, &Core::onVolumeSlider));
trayIcon->signal_ask_dialog().connect(sigc::mem_fun(*core, &Core::runAboutDialog));
trayIcon->signal_ask_settings().connect(sigc::mem_fun(*core, &Core::runSettings));
trayIcon->signal_on_restore().connect(sigc::mem_fun(*sliderWindow, &SliderWindow::setWindowPosition));
trayIcon->signal_save_settings().connect(sigc::mem_fun(*core, &Core::saveSettings));
trayIcon->signal_on_mute().connect(sigc::mem_fun(*core, &Core::soundMuted));
trayIcon->signal_value_changed().connect(sigc::mem_fun(*core, &Core::onTrayIconScroll));
sliderWindow->set_visible(false);
#ifndef IS_GTK_2
return app->run();
#else
Gtk::Main::run();
#endif
}
delete sliderWindow;
return 0;
}