dynwatch

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/events.c	Wed May 18 05:53:29 2011 +0300
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 +This file is part of dynwatch, a win32 system tray applet which
     1.6 +updates automatically the dyndns entry of quake.gr.
     1.7 +
     1.8 +Copyright (c) 2005 John Tsiombikas <nuclear@siggraph.org>
     1.9 +
    1.10 +This program is free software; you can redistribute it and/or modify
    1.11 +it under the terms of the GNU General Public License as published by
    1.12 +the Free Software Foundation; either version 2 of the License, or
    1.13 +(at your option) any later version.
    1.14 +
    1.15 +This program is distributed in the hope that it will be useful,
    1.16 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 +GNU General Public License for more details.
    1.19 +
    1.20 +You should have received a copy of the GNU General Public License
    1.21 +along with this program; if not, write to the Free Software
    1.22 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.23 +*/
    1.24 +
    1.25 +#include <windows.h>
    1.26 +#include "watch.h"
    1.27 +#include "gui.h"
    1.28 +
    1.29 +extern int running;
    1.30 +
    1.31 +long CALLBACK win_proc(HWND win, unsigned int msg, unsigned int wparam, long lparam) {
    1.32 +	switch(msg) {
    1.33 +	case WM_CLOSE:
    1.34 +		DestroyWindow(win);
    1.35 +		PostQuitMessage(0);
    1.36 +		return 0;
    1.37 +
    1.38 +	case WM_COMMAND:
    1.39 +		if((HWND)lparam == bn_tray) {
    1.40 +			trayfied = !trayfied;
    1.41 +			if(trayfied && !running) {
    1.42 +				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!");
    1.43 +			}
    1.44 +			tray(trayfied);
    1.45 +		}
    1.46 +
    1.47 +		if((HWND)lparam == bn_exit) {
    1.48 +			DestroyWindow(win);
    1.49 +			PostQuitMessage(0);
    1.50 +		}
    1.51 +
    1.52 +		if((HWND)lparam == bn_config) {
    1.53 +			en_set_text(en_dnshost, dhost);
    1.54 +			en_set_text(en_user, user);
    1.55 +			en_set_text(en_pass, pass);
    1.56 +			en_set_text(en_hosts, hosts);
    1.57 +			ShowWindow(win_cfg, 1);
    1.58 +		}
    1.59 +		return 0;
    1.60 +
    1.61 +	case WM_USER:
    1.62 +		if(lparam == WM_LBUTTONUP) {
    1.63 +			trayfied = !trayfied;
    1.64 +			tray(trayfied);
    1.65 +		}
    1.66 +		return 0;
    1.67 +
    1.68 +	case WM_TIMER:
    1.69 +		if(need_update()) {
    1.70 +			update_dns();
    1.71 +		}
    1.72 +		return 0;
    1.73 +
    1.74 +	default:
    1.75 +		break;
    1.76 +	}
    1.77 +
    1.78 +	return DefWindowProc(win, msg, wparam, lparam);
    1.79 +}
    1.80 +
    1.81 +
    1.82 +int empty_str(const char *str) {
    1.83 +	while(*str) if(isalnum(*str++)) return 0;
    1.84 +	return 1;
    1.85 +}
    1.86 +
    1.87 +long CALLBACK cfg_proc(HWND win, unsigned int msg, unsigned int wparam, long lparam) {
    1.88 +	switch(msg) {
    1.89 +	case WM_COMMAND:
    1.90 +		if((HWND)lparam == bn_ok) {
    1.91 +			if(empty_str(en_get_text(en_dnshost)) ||
    1.92 +				empty_str(en_get_text(en_user)) ||
    1.93 +				empty_str(en_get_text(en_pass)) ||
    1.94 +				empty_str(en_get_text(en_hosts))) {
    1.95 +				err_msg("you must fill all the fields of this configuration dialog!");
    1.96 +				return 0;
    1.97 +			}
    1.98 +
    1.99 +			strncpy(dhost, en_get_text(en_dnshost), 256);
   1.100 +			strncpy(user, en_get_text(en_user), 256);
   1.101 +			strncpy(pass, en_get_text(en_pass), 256);
   1.102 +			strncpy(hosts, en_get_text(en_hosts), 256);
   1.103 +
   1.104 +			save_config();
   1.105 +			running = 1;
   1.106 +			ShowWindow(win_cfg, 0);
   1.107 +		}
   1.108 +
   1.109 +		if((HWND)lparam == bn_cancel) {
   1.110 +			ShowWindow(win_cfg, 0);
   1.111 +		}
   1.112 +		return 0;
   1.113 +
   1.114 +	default:
   1.115 +		break;
   1.116 +	}
   1.117 +
   1.118 +	return DefWindowProc(win, msg, wparam, lparam);
   1.119 +}