dynwatch

view events.c @ 0:ce3c5e4c75bf

dynwatch DynDNS updater for windows
author John Tsiombikas <nuclear@siggraph.org>
date Wed, 18 May 2011 05:53:29 +0300
parents
children
line source
1 /*
2 This file is part of dynwatch, a win32 system tray applet which
3 updates automatically the dyndns entry of quake.gr.
5 Copyright (c) 2005 John Tsiombikas <nuclear@siggraph.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
22 #include <windows.h>
23 #include "watch.h"
24 #include "gui.h"
26 extern int running;
28 long CALLBACK win_proc(HWND win, unsigned int msg, unsigned int wparam, long lparam) {
29 switch(msg) {
30 case WM_CLOSE:
31 DestroyWindow(win);
32 PostQuitMessage(0);
33 return 0;
35 case WM_COMMAND:
36 if((HWND)lparam == bn_tray) {
37 trayfied = !trayfied;
38 if(trayfied && !running) {
39 info_msg("If you want to have this program operational, you MUST configure first.\nGoing to the tray but keep in mind that I can't do anything at this point without configuration!");
40 }
41 tray(trayfied);
42 }
44 if((HWND)lparam == bn_exit) {
45 DestroyWindow(win);
46 PostQuitMessage(0);
47 }
49 if((HWND)lparam == bn_config) {
50 en_set_text(en_dnshost, dhost);
51 en_set_text(en_user, user);
52 en_set_text(en_pass, pass);
53 en_set_text(en_hosts, hosts);
54 ShowWindow(win_cfg, 1);
55 }
56 return 0;
58 case WM_USER:
59 if(lparam == WM_LBUTTONUP) {
60 trayfied = !trayfied;
61 tray(trayfied);
62 }
63 return 0;
65 case WM_TIMER:
66 if(need_update()) {
67 update_dns();
68 }
69 return 0;
71 default:
72 break;
73 }
75 return DefWindowProc(win, msg, wparam, lparam);
76 }
79 int empty_str(const char *str) {
80 while(*str) if(isalnum(*str++)) return 0;
81 return 1;
82 }
84 long CALLBACK cfg_proc(HWND win, unsigned int msg, unsigned int wparam, long lparam) {
85 switch(msg) {
86 case WM_COMMAND:
87 if((HWND)lparam == bn_ok) {
88 if(empty_str(en_get_text(en_dnshost)) ||
89 empty_str(en_get_text(en_user)) ||
90 empty_str(en_get_text(en_pass)) ||
91 empty_str(en_get_text(en_hosts))) {
92 err_msg("you must fill all the fields of this configuration dialog!");
93 return 0;
94 }
96 strncpy(dhost, en_get_text(en_dnshost), 256);
97 strncpy(user, en_get_text(en_user), 256);
98 strncpy(pass, en_get_text(en_pass), 256);
99 strncpy(hosts, en_get_text(en_hosts), 256);
101 save_config();
102 running = 1;
103 ShowWindow(win_cfg, 0);
104 }
106 if((HWND)lparam == bn_cancel) {
107 ShowWindow(win_cfg, 0);
108 }
109 return 0;
111 default:
112 break;
113 }
115 return DefWindowProc(win, msg, wparam, lparam);
116 }