settings, token entry, receive READY

This commit is contained in:
ouwou
2020-08-19 01:07:55 -04:00
parent 18af78e6af
commit 3c3fe3b9f7
15 changed files with 360 additions and 36 deletions

View File

@@ -1,44 +1,92 @@
#include <gtkmm.h>
#include "discord/discord.hpp"
#include "windows/mainwindow.hpp"
#include <memory>
#include <string>
#include "discord/discord.hpp"
#include "dialogs/token.hpp"
#include "abaddon.hpp"
#ifdef _WIN32
#pragma comment(lib, "crypt32.lib")
#endif
int Abaddon::DoMainLoop() {
m_gtk_app = Gtk::Application::create("com.github.lorpus.abaddon");
MainWindow main;
main.SetAbaddon(this);
main.set_title("Abaddon");
main.show();
m_gtk_app->signal_shutdown().connect([&]() {
m_discord.Stop();
});
/*sigc::connection draw_signal_handler = main.signal_draw().connect([&](const Cairo::RefPtr<Cairo::Context> &ctx) -> bool {
draw_signal_handler.disconnect();
return false;
});*/
return m_gtk_app->run(main);
Abaddon::Abaddon()
: m_settings("abaddon.ini") {
m_discord.SetAbaddon(this);
LoadFromSettings();
}
void Abaddon::StartDiscordThread() {
Abaddon::~Abaddon() {
m_settings.Close();
m_discord.Stop();
}
int Abaddon::StartGTK() {
m_gtk_app = Gtk::Application::create("com.github.lorpus.abaddon");
m_main_window = std::make_unique<MainWindow>();
m_main_window->SetAbaddon(this);
m_main_window->set_title("Abaddon");
m_main_window->show();
m_main_window->UpdateMenuStatus();
m_gtk_app->signal_shutdown().connect([&]() {
StopDiscord();
});
if (!m_settings.IsValid()) {
Gtk::MessageDialog dlg(*m_main_window, "The settings file could not be created!", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dlg.run();
}
return m_gtk_app->run(*m_main_window);
}
void Abaddon::LoadFromSettings() {
std::string token = m_settings.GetSetting("discord", "token");
if (token.size()) {
m_discord_token = token;
}
}
void Abaddon::StartDiscord() {
m_discord.Start();
}
void Abaddon::StopDiscord() {
m_discord.Stop();
}
bool Abaddon::IsDiscordActive() const {
return m_discord.IsStarted();
}
std::string Abaddon::GetDiscordToken() const {
return m_discord_token;
}
void Abaddon::ActionConnect() {
if (!m_discord.IsStarted())
StartDiscordThread();
StartDiscord();
m_main_window->UpdateMenuStatus();
}
void Abaddon::ActionDisconnect() {
if (m_discord.IsStarted())
StopDiscord();
m_main_window->UpdateMenuStatus();
}
void Abaddon::ActionSetToken() {
TokenDialog dlg(*m_main_window);
auto response = dlg.run();
if (response == Gtk::RESPONSE_OK) {
m_discord_token = dlg.GetToken();
m_main_window->UpdateMenuStatus();
m_settings.SetSetting("discord", "token", m_discord_token);
}
}
int main(int argc, char **argv) {
Abaddon abaddon;
return abaddon.DoMainLoop();
return abaddon.StartGTK();
}