linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #06862
[Branch ~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin] Rev 27: fix showing/hiding the dialog
------------------------------------------------------------
revno: 27
committer: poy <poy@xxxxxxxxxx>
branch nick: DevPlugin
timestamp: Mon 2013-05-13 21:07:51 +0200
message:
fix showing/hiding the dialog
modified:
src/GUI.cpp
src/GUI.h
src/Plugin.cpp
src/Plugin.h
--
lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin
Your team Dcplusplus-team is subscribed to branch lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin/+edit-subscription
=== modified file 'src/GUI.cpp'
--- src/GUI.cpp 2013-05-05 13:49:41 +0000
+++ src/GUI.cpp 2013-05-13 19:07:51 +0000
@@ -18,7 +18,6 @@
#include "stdafx.h"
#include "GUI.h"
-#include "Plugin.h"
#include <pluginsdk/Config.h>
#include <pluginsdk/Util.h>
@@ -54,6 +53,8 @@
using namespace dwt;
+bool GUI::unloading = false;
+
WindowPtr window;
TablePtr table;
ComboBoxPtr filterW;
@@ -76,6 +77,13 @@
}
void GUI::create() {
+ if(window) {
+ window->setFocus();
+ return;
+ }
+
+ Config::setConfig("Dialog", true);
+
Application::init();
{
@@ -94,8 +102,8 @@
window->onClosing([]() -> bool {
window = nullptr;
- Plugin::dlgClosed();
Application::uninit();
+ if(!unloading) { Config::setConfig("Dialog", false); }
return true;
});
window->onDestroy([this] { clear(); });
=== modified file 'src/GUI.h'
--- src/GUI.h 2013-01-29 18:42:08 +0000
+++ src/GUI.h 2013-05-13 19:07:51 +0000
@@ -38,6 +38,8 @@
void write(bool hubOrUser, bool sending, string ip, decltype(ConnectionData().port) port, string peer, string message);
void close();
+ static bool unloading;
+
private:
void timer();
void initFilter();
=== modified file 'src/Plugin.cpp'
--- src/Plugin.cpp 2013-05-13 17:40:32 +0000
+++ src/Plugin.cpp 2013-05-13 19:07:51 +0000
@@ -40,11 +40,21 @@
using dcapi::UI;
using dcapi::Util;
+const string showCommand = "Show the dialog";
+const string hideCommand = "Hide the dialog";
+
Plugin::Plugin() {
}
Plugin::~Plugin() {
- clearHooks();
+ Hooks::clear();
+
+ if(UI::handle()) {
+ UI::removeCommand(showCommand);
+ UI::removeCommand(hideCommand);
+ }
+
+ GUI::unloading = true;
}
Plugin* instance;
@@ -73,34 +83,6 @@
}
}
-void Plugin::dlgClosed() {
- instance->close();
-}
-
-void Plugin::addHooks() {
- Hooks::Network::onHubDataIn([this](HubDataPtr hHub, char* message, bool&) { return onHubDataIn(hHub, message); });
- Hooks::Network::onHubDataOut([this](HubDataPtr hHub, char* message, bool&) { return onHubDataOut(hHub, message); });
- Hooks::Network::onClientDataIn([this](ConnectionDataPtr hConn, char* message, bool&) { return onClientDataIn(hConn, message); });
- Hooks::Network::onClientDataOut([this](ConnectionDataPtr hConn, char* message, bool&) { return onClientDataOut(hConn, message); });
- Hooks::UI::onChatCommand([this](HubDataPtr hHub, CommandDataPtr cmd, bool&) { return onChatCommand(hHub, cmd); });
-}
-
-void Plugin::clearHooks() {
- Hooks::clear();
-}
-
-void Plugin::start() {
- gui.create();
- addHooks();
- Config::setConfig("Enabled", true);
-}
-
-void Plugin::close() {
- Config::setConfig("Enabled", false);
- clearHooks();
- gui.close();
-}
-
bool Plugin::onLoad(DCCorePtr core, bool install) {
/* Initialization phase. Initiate additional interfaces that you may have included from the
plugin SDK. */
@@ -111,27 +93,25 @@
if(install) {
// This only executes when the plugin has been installed for the first time.
- Config::setConfig("Enabled", true);
+ Config::setConfig("Dialog", true);
Logger::log("The dev plugin has been installed; check the plugins menu and the /raw chat command.");
}
// Start the plugin logic here; add hooks with functions from the Hooks interface.
- if(Config::getBoolConfig("Enabled")) {
- start();
- }
+ Hooks::Network::onHubDataIn([this](HubDataPtr hHub, char* message, bool&) { return onHubDataIn(hHub, message); });
+ Hooks::Network::onHubDataOut([this](HubDataPtr hHub, char* message, bool&) { return onHubDataOut(hHub, message); });
+ Hooks::Network::onClientDataIn([this](ConnectionDataPtr hConn, char* message, bool&) { return onClientDataIn(hConn, message); });
+ Hooks::Network::onClientDataOut([this](ConnectionDataPtr hConn, char* message, bool&) { return onClientDataOut(hConn, message); });
+ Hooks::UI::onChatCommand([this](HubDataPtr hHub, CommandDataPtr cmd, bool&) { return onChatCommand(hHub, cmd); });
+
+ Hooks::UI::onCreated([this](dcptr_t, bool&) -> bool { if(Config::getBoolConfig("Dialog")) { gui.create(); } return false; });
+ UI::addCommand(showCommand, [this] { gui.create(); }, string());
+ UI::addCommand(hideCommand, [this] { gui.close(); }, string());
return true;
}
-void Plugin::onSwitched() {
- if(Hooks::empty()) {
- start();
- } else {
- close();
- }
-}
-
bool Plugin::onHubDataIn(HubDataPtr hHub, char* message) {
gui.write(true, false, hHub->ip, hHub->port, "Hub <" + string(hHub->url) + ">", message);
return false;
=== modified file 'src/Plugin.h'
--- src/Plugin.h 2013-05-13 17:40:32 +0000
+++ src/Plugin.h 2013-05-13 19:07:51 +0000
@@ -28,20 +28,11 @@
public:
static Bool DCAPI main(PluginState state, DCCorePtr core, dcptr_t);
- static void dlgClosed();
-
private:
Plugin();
~Plugin();
- void addHooks();
- void clearHooks();
-
- void start();
- void close();
-
bool onLoad(DCCorePtr core, bool install);
- void onSwitched();
bool onHubDataIn(HubDataPtr hHub, char* message);
bool onHubDataOut(HubDataPtr hHub, char* message);
bool onClientDataIn(ConnectionDataPtr hConn, char* message);