root / trunk / base / ngobject.c @ 1834
History | View | Annotate | Download (3.7 KB)
| 1 | 
                  /* 
                 | 
              
|---|---|
| 2 | 
                  Copyright (C) 2005-2010 Erik van Pienbroek  | 
              
| 3 | 
                   | 
              
| 4 | 
                  This program is free software; you can redistribute it and/or modify  | 
              
| 5 | 
                  it under the terms of the GNU General Public License as published by  | 
              
| 6 | 
                  the Free Software Foundation; either version 2 of the License, or  | 
              
| 7 | 
                  (at your option) any later version.  | 
              
| 8 | 
                   | 
              
| 9 | 
                  This program is distributed in the hope that it will be useful,  | 
              
| 10 | 
                  but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
              
| 11 | 
                  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  | 
              
| 12 | 
                  GNU General Public License for more details.  | 
              
| 13 | 
                   | 
              
| 14 | 
                  You should have received a copy of the GNU General Public License  | 
              
| 15 | 
                  along with this program; if not, write to the Free Software  | 
              
| 16 | 
                  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  | 
              
| 17 | 
                  */  | 
              
| 18 | 
                   | 
              
| 19 | 
                  #ifdef HAVE_CONFIG_H
                 | 
              
| 20 | 
                  #include "config.h"  | 
              
| 21 | 
                  #endif
                 | 
              
| 22 | 
                   | 
              
| 23 | 
                  #include  | 
              
| 24 | 
                  #include  | 
              
| 25 | 
                  #include "nntpgrab_utils.h"  | 
              
| 26 | 
                   | 
              
| 27 | 
                  #ifdef HAVE_SOUP
                 | 
              
| 28 | 
                  #include  | 
              
| 29 | 
                  #endif
                 | 
              
| 30 | 
                  #ifdef HAVE_SOUP_GNOME
                 | 
              
| 31 | 
                  #include  | 
              
| 32 | 
                  #endif
                 | 
              
| 33 | 
                  #if defined(WIN32) && GLIB_CHECK_VERSION(2,27,1)  | 
              
| 34 | 
                  #include  | 
              
| 35 | 
                  #include  | 
              
| 36 | 
                  #endif
                 | 
              
| 37 | 
                   | 
              
| 38 | 
                  NGTypeInstance* ng_type_check_instance_cast (NGTypeInstance *instance,  | 
              
| 39 | 
                  NGType iface_type)  | 
              
| 40 | 
                  {
                 | 
              
| 41 | 
                      return (NGTypeInstance*) g_type_check_instance_cast((GTypeInstance*) instance, (GType) iface_type);
                 | 
              
| 42 | 
                  }  | 
              
| 43 | 
                   | 
              
| 44 | 
                  #if defined(WIN32) && GLIB_CHECK_VERSION(2,27,1)  | 
              
| 45 | 
                  static gchar *
                 | 
              
| 46 | 
                  get_special_folder (int csidl)
                 | 
              
| 47 | 
                  {
                 | 
              
| 48 | 
                      wchar_t path[MAX_PATH+1];
                 | 
              
| 49 | 
                  HRESULT hr;  | 
              
| 50 | 
                      LPITEMIDLIST pidl = NULL;
                 | 
              
| 51 | 
                  BOOL b;  | 
              
| 52 | 
                      gchar *retval = NULL;
                 | 
              
| 53 | 
                   | 
              
| 54 | 
                      hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl);
                 | 
              
| 55 | 
                      if (hr == S_OK) {
                 | 
              
| 56 | 
                  b = SHGetPathFromIDListW (pidl, path);  | 
              
| 57 | 
                          if (b)
                 | 
              
| 58 | 
                  retval = g_utf16_to_utf8 (path, -1, NULL, NULL, NULL);  | 
              
| 59 | 
                  CoTaskMemFree (pidl);  | 
              
| 60 | 
                  }  | 
              
| 61 | 
                      return retval;
                 | 
              
| 62 | 
                  }  | 
              
| 63 | 
                   | 
              
| 64 | 
                  static void  | 
              
| 65 | 
                  move_win32_configuration_files_if_necessary(void)
                 | 
              
| 66 | 
                  {
                 | 
              
| 67 | 
                      char *appdata_dir = get_special_folder (CSIDL_APPDATA);
                 | 
              
| 68 | 
                  char *config_dir = g_build_path(G_DIR_SEPARATOR_S, appdata_dir, "NNTPGrab", NULL);  | 
              
| 69 | 
                   | 
              
| 70 | 
                      if (g_file_test(config_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
                 | 
              
| 71 | 
                  char *config_dir_new = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "NNTPGrab", NULL);  | 
              
| 72 | 
                  g_rename(config_dir, config_dir_new);  | 
              
| 73 | 
                  g_free(config_dir_new);  | 
              
| 74 | 
                  }  | 
              
| 75 | 
                   | 
              
| 76 | 
                  g_free(config_dir);  | 
              
| 77 | 
                  g_free(appdata_dir);  | 
              
| 78 | 
                  }  | 
              
| 79 | 
                  #endif
                 | 
              
| 80 | 
                   | 
              
| 81 | 
                  void nntpgrab_utils_perform_base_initialization(void)  | 
              
| 82 | 
                  {
                 | 
              
| 83 | 
                  if (!g_thread_supported ()) g_thread_init (NULL);  | 
              
| 84 | 
                  g_type_init();  | 
              
| 85 | 
                   | 
              
| 86 | 
                  #ifdef HAVE_SOUP
                 | 
              
| 87 | 
                      /* Due to a bug in libsoup we need to make sure that all GObject's 
                 | 
              
| 88 | 
                  * are initialized from the main thread to avoid a deadlock when libsoup  | 
              
| 89 | 
                  * is called for the first time from a different thread */  | 
              
| 90 | 
                  SoupSession *session = soup_session_sync_new();  | 
              
| 91 | 
                   | 
              
| 92 | 
                  #if 0 
                 | 
              
| 93 | 
                  SoupLogger *logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);  | 
              
| 94 | 
                  soup_session_add_feature(session, SOUP_SESSION_FEATURE(logger));  | 
              
| 95 | 
                  g_object_unref(logger);  | 
              
| 96 | 
                  #endif  | 
              
| 97 | 
                   | 
              
| 98 | 
                  #ifdef HAVE_SOUP_GNOME
                 | 
              
| 99 | 
                      /* Enable proxy support when using GNOME 2.26.0 or higher */
                 | 
              
| 100 | 
                  soup_session_add_feature_by_type(session, SOUP_TYPE_GNOME_FEATURES_2_26);  | 
              
| 101 | 
                  #endif
                 | 
              
| 102 | 
                   | 
              
| 103 | 
                  #ifdef HAVE_SOUP_GZIP
                 | 
              
| 104 | 
                      /* Enable gzip compression */
                 | 
              
| 105 | 
                  soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);  | 
              
| 106 | 
                  #endif
                 | 
              
| 107 | 
                   | 
              
| 108 | 
                  g_object_unref(session);  | 
              
| 109 | 
                  #endif
                 | 
              
| 110 | 
                   | 
              
| 111 | 
                  #if defined(WIN32) && GLIB_CHECK_VERSION(2,27,1)  | 
              
| 112 | 
                      /* As of GLib 2.27.1 the return value of the function g_get_user_data_dir() 
                 | 
              
| 113 | 
                  * was changed to return CSIDL_LOCAL_APPDATA instead of CSIDL_APPDATA on Win32.  | 
              
| 114 | 
                  * To prevent a broken NNTPGrab configuration, check if there are configuration  | 
              
| 115 | 
                  * files at the old path and move them to the new location if necessary */  | 
              
| 116 | 
                  move_win32_configuration_files_if_necessary();  | 
              
| 117 | 
                  #endif
                 | 
              
| 118 | 
                  }  | 
              
NNTPGrab

