~ubuntu-branches/ubuntu/precise/tickr/precise-backports

« back to all changes in this revision

Viewing changes to src/libetm-0.4.2/win32_specific.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Thomas-Maurin
  • Date: 2011-12-18 00:21:23 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111218002123-6h12joajjpatt170
Tags: 0.5.5-1
* Implement new parameter: <mouse wheel scrolling apply to:
* s = ticker-speed / f = feed-in-list / n = none>.

* Set <ticker pause on mouse-over> as optional.

* Select/highlight and scroll to added URL in the list window.

* Split compute_surface_and_win() code into compute_surface and
  compute_win, because the later is not always necessary. When
  window-always-on-top is disabled, compute_win needs to be run only
  twice at program startup (ie once after gtk_widget_show_all() has been
  called), then whenever params are changed, but not every time a new
  feed is loaded.

* Add preferences (settings) importing/exporting feature.

* 'file' scheme support added in tickr_http.c -> enables reading *and*
  xml-processing of (local) text files (wheras 'open text file' *only*
  read them.)

* 'HTTPS not supported' handling/warning added in tickr_http.c (fix bug:
  program freezes whith HTTP redirects to HTTPS.)

* xml 'quick check' in tickr_http.c:format_quick_check() don't reject
  anymore valid (?) feeds not starting with '<?xml' (like google news.)

* A few little changes in libetm-0.4 -> libetm-0.4.2.

* Use mouse wheel to go to previous/next feed.

* Hide passwords in connection settings window.

* Pause ticker and show feed title in tooltip on mouse-over.

* Renaming all source files: news_*.c/h -> tickr_*/c/h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      libetm-0.4 / win32_specific.c - Copyright (C) Emmanuel Thomas-Maurin 2008-2011
 
3
 *      <manutm007@gmail.com>
 
4
 *
 
5
 *      - win32 specific functions -
 
6
 *
 
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 3 of the License, or
 
10
 *      (at your option) any later version.
 
11
 *
 
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.
 
16
 *
 
17
 *      You should have received a copy of the GNU General Public License
 
18
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#ifdef WIN32_V
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <windows.h>
 
26
#include <rpcdce.h>
 
27
#include <Iphlpapi.h>
 
28
#include <winreg.h>
 
29
#include <shlobj.h>
 
30
#include "libetm.h"
 
31
 
 
32
#define APP_WIN32REG_KEYPATH    "app_win32_registry_keypath"    /* or whatever */
 
33
 
 
34
/* return NULL if error */
 
35
const char *get_appdata_dir()
 
36
{
 
37
        static TCHAR    appdata_dir[MAX_PATH];
 
38
        static int      i = 0;
 
39
 
 
40
        if (i == 0) {
 
41
                i++;
 
42
                if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, appdata_dir) != S_OK)
 
43
                        i++;
 
44
        }
 
45
        if (i == 1)
 
46
                return (const char *)appdata_dir;
 
47
        else
 
48
                return NULL;
 
49
}
 
50
 
 
51
/* return NULL if error */
 
52
const char *get_progfiles_dir()
 
53
{
 
54
        static TCHAR    progfiles_dir[MAX_PATH];
 
55
        static int      i = 0;
 
56
 
 
57
        if (i == 0) {
 
58
                i++;
 
59
                if (SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, 0, progfiles_dir) != S_OK)
 
60
                        i++;
 
61
        }
 
62
        if (i == 1)
 
63
                return (const char *)progfiles_dir;
 
64
        else
 
65
                return NULL;
 
66
}
 
67
 
 
68
/* key_value must be able to store 255 chars */
 
69
int get_key_value_from_win32registry(const char *key_name, char *key_value)
 
70
{
 
71
        char    news_win32regkey_full[128];
 
72
        HKEY    hkey;
 
73
        DWORD   type = REG_SZ, buf_size = 256;
 
74
        LONG    result;
 
75
 
 
76
        str_n_cpy(news_win32regkey_full, APP_WIN32REG_KEYPATH, 64);
 
77
        str_n_cat(news_win32regkey_full, key_name, 63);
 
78
 
 
79
        if ((result = RegOpenKeyEx(HKEY_CURRENT_USER, news_win32regkey_full,
 
80
                        0L, KEY_QUERY_VALUE, &hkey)) == ERROR_SUCCESS) {
 
81
                if (RegQueryValueEx(hkey, NULL, NULL, &type, (unsigned char*)key_value,
 
82
                                &buf_size) == ERROR_SUCCESS) {
 
83
                        RegCloseKey(hkey);
 
84
                        return LIBETM_OK;
 
85
                } else {
 
86
                        RegCloseKey(hkey);
 
87
                        return WIN32REGKEY_NOT_FOUND;
 
88
                }
 
89
        } else {
 
90
                if (result == ERROR_FILE_NOT_FOUND)
 
91
                        return WIN32REGKEY_NOT_FOUND;
 
92
                else
 
93
                        return WIN32REGKEY_OTHER_ERROR;
 
94
        }
 
95
}
 
96
 
 
97
int save_key_value_into_win32registry(const char *key_name, const char *key_value)
 
98
{
 
99
        char    news_win32regkey_full[128];
 
100
        HKEY    hkey;
 
101
        DWORD   disp = 0;
 
102
 
 
103
        str_n_cpy(news_win32regkey_full, APP_WIN32REG_KEYPATH, 64);
 
104
        str_n_cat(news_win32regkey_full, key_name, 63);
 
105
 
 
106
        if (RegCreateKeyEx(HKEY_CURRENT_USER, news_win32regkey_full, 0L,
 
107
                        NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hkey, &disp)
 
108
                        == ERROR_SUCCESS) {
 
109
                if (RegSetValueEx(hkey, NULL, 0L, REG_SZ, (unsigned char *)TEXT(key_value),
 
110
                                256) == ERROR_SUCCESS) {
 
111
                        RegCloseKey(hkey);
 
112
                        return LIBETM_OK;
 
113
                } else {
 
114
                        RegCloseKey(hkey);
 
115
                        return  WIN32REGKEY_SAVE_ERROR;
 
116
                }
 
117
        } else
 
118
                return WIN32REGKEY_CREATE_ERROR;
 
119
}
 
120
 
 
121
/* return NULL if error */
 
122
const char *get_default_browser_from_win32registry()
 
123
{
 
124
        static char     browser_cmd[512];
 
125
        HKEY            hkey;
 
126
        DWORD           type = REG_SZ, buf_size = 512;
 
127
        LONG            result;
 
128
 
 
129
        if ((result = RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\\shell\\open\\command",
 
130
                        0L, KEY_QUERY_VALUE, &hkey)) == ERROR_SUCCESS) {
 
131
                if (RegQueryValueEx(hkey, NULL, NULL, &type, (unsigned char*)browser_cmd,
 
132
                                &buf_size) == ERROR_SUCCESS) {
 
133
                        RegCloseKey(hkey);
 
134
                        return (const char *)browser_cmd;
 
135
                } else {
 
136
                        RegCloseKey(hkey);
 
137
                        return NULL;
 
138
                }
 
139
        } else
 
140
                return NULL;
 
141
}
 
142
 
 
143
/* return -1 if error */
 
144
int get_win32_taskbar_height()
 
145
{
 
146
        HWND    hwnd;
 
147
        RECT    r;
 
148
        LPRECT  lpRect = &r;
 
149
 
 
150
        if ((hwnd = FindWindow("Shell_traywnd", "")) != NULL) {
 
151
                if (GetWindowRect(hwnd, lpRect))
 
152
                        return (int) (lpRect->bottom - lpRect->top);
 
153
        }
 
154
        return -1;
 
155
}
 
156
 
 
157
/* find up to 15 mac addresses for this computer
 
158
 * return NULL if error */
 
159
/*const char **find_mac_addresses()
 
160
{
 
161
        IP_ADAPTER_INFO         *adapter_info;
 
162
        ULONG                   buf_len = sizeof(adapter_info);
 
163
        PIP_ADAPTER_INFO        p_adapter_info;
 
164
        static char             macaddr[16][256], tmp[3];
 
165
        static char             *p_macaddr[16];
 
166
        unsigned int            i, j = 0;
 
167
 
 
168
        adapter_info = (IP_ADAPTER_INFO *)malloc2(sizeof(IP_ADAPTER_INFO));
 
169
        buf_len = sizeof(IP_ADAPTER_INFO);
 
170
        // initial call is supposed to fail
 
171
        if (GetAdaptersInfo(adapter_info, &buf_len) != ERROR_SUCCESS) {
 
172
                free2(adapter_info);
 
173
                adapter_info = (IP_ADAPTER_INFO *)malloc2(buf_len);
 
174
        }
 
175
        // 2nd call
 
176
        if (GetAdaptersInfo(adapter_info, &buf_len) != ERROR_SUCCESS) {
 
177
                free2(adapter_info);
 
178
                return NULL;
 
179
        } else {
 
180
                p_adapter_info = (PIP_ADAPTER_INFO)adapter_info;
 
181
                while (p_adapter_info && j < 15) {
 
182
                        macaddr[j][0] = '\0';
 
183
                        for (i = 0; i < 127 && i < p_adapter_info->AddressLength; i++) {
 
184
                                snprintf(tmp, 3, "%02X", p_adapter_info->Address[i]);
 
185
                                str_n_cat(macaddr[j], tmp, 2);
 
186
                        }
 
187
                        p_macaddr[j] = macaddr[j];
 
188
                        j++;
 
189
                        p_adapter_info = p_adapter_info->Next;
 
190
                }
 
191
                free2(adapter_info);
 
192
                p_macaddr[j] = NULL;
 
193
        }
 
194
        return (const char **)p_macaddr;
 
195
}*/
 
196
#endif