annotate console/libgnt/test/wm.c @ 14945:51b7d367a693

[gaim-migrate @ 17717] Credit is a good thing committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 10 Nov 2006 04:54:11 +0000
parents 0a0d2a1fd2bc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13960
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include <gmodule.h>
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 #include <gnt.h>
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 #include <gntbox.h>
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 #include <gntentry.h>
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 #include <gntlabel.h>
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 static gboolean
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 key_pressed(GntEntry *entry, const char *text, gpointer null)
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 {
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 if (*text != '\r')
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 return FALSE;
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 {
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
15 const char *cmd;
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
16 void *handle;
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 void (*func)();
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 cmd = gnt_entry_get_text(entry);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20 handle = g_module_open(cmd, G_MODULE_BIND_LOCAL);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 if (handle && g_module_symbol(handle, "main", (gpointer)&func))
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 {
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13960
diff changeset
23 char *argv[] = {cmd, NULL};
13960
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 gnt_entry_clear(entry);
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13960
diff changeset
25 func(1, argv);
13960
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26 }
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 else
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 {
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 GntWidget *widget = gnt_vbox_new(FALSE);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 gnt_box_set_toplevel(GNT_BOX(widget), TRUE);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 gnt_box_set_title(GNT_BOX(widget), "Error");
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 gnt_box_add_widget(GNT_BOX(widget), gnt_label_new("Could not execute."));
13964
0a0d2a1fd2bc [gaim-migrate @ 16520]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13960
diff changeset
33 gnt_box_add_widget(GNT_BOX(widget), gnt_label_new(g_module_error()));
13960
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 gnt_widget_show(widget);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 }
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 }
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39 return TRUE;
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 }
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 int main()
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 {
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 GntWidget *window, *entry;
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 freopen(".error", "w", stderr);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 gnt_init();
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 window = gnt_hbox_new(FALSE);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 gnt_box_add_widget(GNT_BOX(window), gnt_label_new("Command"));
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54 entry = gnt_entry_new(NULL);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55 g_signal_connect(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), NULL);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 gnt_box_add_widget(GNT_BOX(window), entry);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 gnt_widget_set_position(window, 0, getmaxy(stdscr) - 2);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 gnt_widget_show(window);
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 gnt_main();
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 gnt_quit();
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65 return 0;
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66 }
a06f7495af6f [gaim-migrate @ 16513]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67