diff options
author | lloyd <[email protected]> | 2006-12-14 11:13:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-12-14 11:13:34 +0000 |
commit | ff6bd6e769e35ae5c0dad671e5afdc182994a076 (patch) | |
tree | 7e57a854f229c2973d412ad15d38e01ca43399d9 /misc/gtk | |
parent | 2b32d88fabd0cf45cb42981dd03258b39d1828c4 (diff) |
Update the GTK example to use the new pulse interface.
Diffstat (limited to 'misc/gtk')
-rw-r--r-- | misc/gtk/Makefile | 2 | ||||
-rw-r--r-- | misc/gtk/dsa.cpp | 28 | ||||
-rw-r--r-- | misc/gtk/readme.txt | 27 |
3 files changed, 30 insertions, 27 deletions
diff --git a/misc/gtk/Makefile b/misc/gtk/Makefile index d436244a4..10e069bb3 100644 --- a/misc/gtk/Makefile +++ b/misc/gtk/Makefile @@ -3,7 +3,7 @@ LIBS=$(shell botan-config --libs) $(shell pkg-config --libs gtk+-2.0) IFLAGS=$(shell botan-config --cflags) $(shell pkg-config --cflags gtk+-2.0) CXX = g++ -CXXFLAGS=-Wall -W $(IFLAGS) +CXXFLAGS = -Wall -W $(IFLAGS) dsa: gtk_ui.o dsa.o $(CXX) $^ $(LIBS) -o $@ diff --git a/misc/gtk/dsa.cpp b/misc/gtk/dsa.cpp index ed2289c52..dff547737 100644 --- a/misc/gtk/dsa.cpp +++ b/misc/gtk/dsa.cpp @@ -6,7 +6,7 @@ The major points of interest (assuming what you care about is how to use Botan from a GUI, and not looking at my terrible GTK code) are gtk_ui.cpp - and, in this file, gtk_pulse(), gen_key(), and get_key(): + and, in this file, GTK_Pulse, gen_key(), and get_key(): gtk_ui.cpp and get_key() show how to get a passphrase from a user for decrypting (well, in theory, anything), but in this case, PKCS #8 private @@ -15,7 +15,7 @@ double duty, for getting passphrases for encryption as well (in do_save_key). - gen_key() and gtk_pulse() show how to do an activity meter while doing a + gen_key() and GTK_Pulse show how to do an activity meter while doing a long-term operation inside Botan. Since, typically, the only operations which take a long time and can't be broken up into smaller parts are prime generation/testing, that is currently where the pulse hooks are @@ -31,16 +31,13 @@ #include <memory> #include <botan/botan.h> +#include <botan/libstate.h> #include <botan/look_pk.h> #include <botan/filters.h> #include <botan/dsa.h> // we don't have a 'using namespace' here, so it's easy to grep for code that // is actually dealing with the library (rather than messing around with GTK). -#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,4,4) - #error "You need a more recent version of Botan (at least 1.4.4)" -#endif - #include <gtk/gtk.h> #include "gtk_ui.h" @@ -225,12 +222,19 @@ static void sign_buffer() /************************************************* * GTK+ pulse callback * *************************************************/ -static void gtk_pulse(Botan::UI::Pulse_Type, void*) +class GTK_Pulse : public Botan::Library_State::UI { - /* We need this to flush the udpates, otherwise GTK+ will wait until we're - done with the computation before doing any updates (generally the right - thing, but not with a progress bar). + public: + void pulse(Botan::Pulse_Type); + }; + +void GTK_Pulse::pulse(Botan::Pulse_Type) + { + /* We need this to flush the updates, otherwise GTK+ will wait until we're + done with the computation before doing any updates (generally the right + thing, but not with a progress bar). */ + while(gtk_events_pending()) gtk_main_iteration(); } @@ -289,7 +293,7 @@ static void gen_key() the progress bar. That's because the amount of time between pulses from the library is rather irregular, so the progress bar looks jerky. */ - Botan::UI::set_pulse(gtk_pulse); + Botan::global_state().set_ui(new GTK_Pulse); /* Not generally recommended, since it's slow and there's not much point. However, *because* it's slow, we'll want to put up a progress bar or @@ -300,7 +304,7 @@ static void gen_key() key = new Botan::DSA_PrivateKey(group); gtk_timeout_remove(timer_id); - Botan::UI::set_pulse(0); // unset the pulse function + Botan::global_state().set_ui(0); // unset the pulse function gtk_widget_destroy(dialog); diff --git a/misc/gtk/readme.txt b/misc/gtk/readme.txt index e95fe4d58..4f3691166 100644 --- a/misc/gtk/readme.txt +++ b/misc/gtk/readme.txt @@ -1,19 +1,18 @@ This is an example of how to use Botan in a GUI. You need at least -Botan 1.4.x. +Botan 1.6.0. -You'll also need GTK+ 2.x (tested with GTK+ 2.2 and 2.6). Keep in mind -that I was learning GTK as I was writing this code, so it is not -exactly the best GTK code you're likely to see. +You'll also need GTK+ 2.x (tested with GTK+ 2.10; should work with +most versions). Keep in mind that I was learning GTK as I was writing +this code, so it is not exactly the best GTK code you're likely to +see. -dsa.cpp is the main GTK+ driver. It has some comments at the top which point -out major areas of interest. +dsa.cpp is the main GTK+ driver. It has some comments at the top which +point out major areas of interest. -gtk_ui.* implement a User_Interface object that opens up a GTK+ dialog box that -asks the user for their passphrase. It works pretty well, the only major -deficiency is a fixed upper limit on the size of the passphrase (currently 64). -You may want to use this in your own code, assuming you use GTK. If not, it -should at least provide an outline for writing a version for your favorite -windowing system. - -To build, you'll need to have GNU make, or be willing to compile it by hand. +gtk_ui.* implement a User_Interface object that opens up a GTK+ dialog +box that asks the user for their passphrase. It works pretty well, the +only major deficiency is a fixed upper limit on the size of the +passphrase (currently 64). You may want to use this in your own code, +assuming you use GTK. If not, it should at least provide an outline +for writing a version for your favorite windowing system. |