From 534088c3c721654fef662a2d2051d1ff3bbb1c20 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 20 Apr 2022 12:07:48 -0400 Subject: Code simplifications --- src/header.cc | 3 +-- src/mods.cc | 78 ++++++++++++++++++++++++----------------------------------- src/mods.h | 3 --- 3 files changed, 33 insertions(+), 51 deletions(-) diff --git a/src/header.cc b/src/header.cc index 69e0742..58d1700 100644 --- a/src/header.cc +++ b/src/header.cc @@ -170,7 +170,7 @@ void Header::updateMenus() { delVersion->signal_clicked().connect([version, this]() { menuMenu.popdown(); std::vector toDel {version}; - this->mods->uninstallMods(toDel); + libbible::uninstallMod(version); reader->refresh(); updateButtons(); updateMenus(); @@ -199,7 +199,6 @@ void Header::updateMenus() { void Header::showMods() { window->remove(); window->add(*this->mods); - //this->mods->displayMain(); window->show_all_children(); } diff --git a/src/mods.cc b/src/mods.cc index 0f6f498..2123220 100644 --- a/src/mods.cc +++ b/src/mods.cc @@ -99,9 +99,12 @@ void Mods::displayMain() { auto *button = Gtk::manage(new Gtk::Button("Download")); network->pack_start(*button, false, false); button->signal_clicked().connect([this]() { - updateInstallable(); - displayDownload(); - }); + if(! modsAvailable.empty()) { + return; + } + modsAvailable = libbible::downloadModsAvailable(); + displayDownload(); + }); auto *local = Gtk::manage(new Gtk::VBox); hbox->add(*local); label = Gtk::manage(new Gtk::Label); @@ -113,12 +116,14 @@ void Mods::displayMain() { filter->add_mime_type("application/zip"); add->set_filter(filter); add->signal_file_set().connect([this, add]() { - installMods(add->get_filenames()); - this->header->reader->refresh(); - this->header->updateMenus(); - this->header->updateButtons(); - this->header->showText(); - }); + for(auto filename : add->get_filenames()) { + libbible::installModFromZip(filename); + } + this->header->reader->refresh(); + this->header->updateMenus(); + this->header->updateButtons(); + this->header->showText(); + }); window->show_all_children(); } @@ -133,8 +138,8 @@ void Mods::displayDownload() { auto *button = Gtk::manage(new Gtk::Button("Back")); vbox->pack_start(*button, false, false); button->signal_clicked().connect([this]() { - displayMain(); - }); + displayMain(); + }); auto *label = Gtk::manage(new Gtk::Label); label->set_text("Language Selection:"); vbox->pack_start(*label, false, false); @@ -166,48 +171,29 @@ void Mods::displayDownload() { auto *langButton = Gtk::manage(new Gtk::Button(fullLanguage)); langButton->set_relief(Gtk::ReliefStyle::RELIEF_NONE); langButton->signal_clicked().connect([language, fullLanguage, langMenuButton, langMenu, modsSelection, this]() { - langMenu->popdown(); - langMenuButton->set_label(fullLanguage); - for(auto child : modsSelection->get_children()) { + langMenu->popdown(); + langMenuButton->set_label(fullLanguage); + for(auto child : modsSelection->get_children()) { modsSelection->remove(*child); - } - for(string name : modsAvailable[language]) { + } + for(string name : modsAvailable[language]) { auto *installButton = Gtk::manage(new Gtk::Button(name)); installButton->signal_clicked().connect([language, name, this]() { - worker = new std::thread([language, name, this] { - complete = false; - libbible::installModFromInternet(language, name); - complete = true; - dispatcher.emit(); - header->showText(); - }); - }); + worker = new std::thread([language, name, this] { + complete = false; + libbible::installModFromInternet(language, name); + complete = true; + dispatcher.emit(); + header->showText(); + }); + }); modsSelection->pack_start(*installButton, false, false); - } - modsSelection->show_all_children(); - }); + } + modsSelection->show_all_children(); + }); langBox->add(*langButton); } langMenuButton->set_popover(*langMenu); langMenu->show_all_children(); window->show_all_children(); } - -void Mods::installMods(std::vector filenames) { - for(auto filename : filenames) { - libbible::installModFromZip(filename); - } -} - -void Mods::uninstallMods(std::vector modnames) { - for(auto mod : modnames) { - libbible::uninstallMod(mod); - } -} - -void Mods::updateInstallable() { - if(! modsAvailable.empty()) { - return; - } - modsAvailable = libbible::downloadModsAvailable(); -} diff --git a/src/mods.h b/src/mods.h index 7373961..dab5a15 100644 --- a/src/mods.h +++ b/src/mods.h @@ -22,9 +22,6 @@ public: Mods(Header *header, Gtk::Window *window); virtual ~Mods(); - void installMods(std::vector filenames); - void uninstallMods(std::vector modnames); - void updateInstallable(); void displayMain(); void displayDownload(); -- cgit v1.2.3