From 396c66f8f86e5c45968f14320705cd9cce21827c Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Wed, 15 Mar 2006 01:40:10 +0000 Subject: [PATCH] set avatar filechooser defaults to My Pictures in the OS that understand user needs [aka Windows] --- src/common/helpers.py | 45 +++++++++++++++++++++++++++++++++++++ src/filetransfers_window.py | 14 +++++------- src/vcard.py | 2 +- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/common/helpers.py b/src/common/helpers.py index 02df3347e..3571d0384 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -38,6 +38,8 @@ from xmpp_stringprep import nodeprep, resourceprep, nameprep try: import winsound # windows-only built-in module for playing wav + import win32api + import win32con except: pass @@ -533,3 +535,46 @@ def decode_string(string): break return string + +def get_windows_reg_env(varname, default=''): + '''asks for paths commonly used but not exposed as ENVs + in Windows 2003 those are: + 'AppData' = %USERPROFILE%\Application Data (also an ENV) + 'Desktop' = %USERPROFILE%\Desktop + 'Favorites' = %USERPROFILE%\Favorites + 'NetHood' = %USERPROFILE%\NetHood + 'Personal' = D:\My Documents (PATH TO MY DOCUMENTS) + 'PrintHood' = %USERPROFILE%\PrintHood + 'Programs' = %USERPROFILE%\Start Menu\Programs + 'Recent' = %USERPROFILE%\Recent + 'SendTo' = %USERPROFILE%\SendTo + 'Start Menu' = %USERPROFILE%\Start Menu + 'Startup' = %USERPROFILE%\Start Menu\Programs\Startup + 'Templates' = %USERPROFILE%\Templates + 'My Pictures' = D:\My Documents\My Pictures + 'Local Settings' = %USERPROFILE%\Local Settings + 'Local AppData' = %USERPROFILE%\Local Settings\Application Data + 'Cache' = %USERPROFILE%\Local Settings\Temporary Internet Files + 'Cookies' = %USERPROFILE%\Cookies + 'History' = %USERPROFILE%\Local Settings\History + ''' + + if os.name != 'nt': + return '' + + val = default + try: + rkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, +r'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders') + try: + val = str(win32api.RegQueryValueEx(rkey, varname)[0]) + val = win32api.ExpandEnvironmentStrings(v) # expand using environ + except: + pass + finally: + win32api.RegCloseKey(rkey) + return val + +def get_my_pictures_path(): + '''windows-only atm. [Unix lives in the past]''' + return get_windows_reg_env('My Pictures') diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index a3ff1e09b..e1c02e16d 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -1,18 +1,14 @@ ## filetransfers_window.py ## -## Contributors for this file: -## - Yann Le Boulanger -## - Nikos Kouremenos -## - Dimitur Kirov ## -## Copyright (C) 2003-2004 Yann Le Boulanger -## Vincent Hanquez -## Copyright (C) 2005 Yann Le Boulanger -## Vincent Hanquez -## Nikos Kouremenos +## Copyright (C) 2003-2006 Yann Le Boulanger +## Copyright (C) 2005-2006 Yann Le Boulanger +## Copyright (C) 2005-2006 Nikos Kouremenos +## Copyright (C) 2005 ## Dimitur Kirov ## Travis Shirk ## Norman Rasmussen +## Copyright (C) 2004-2005 Vincent Hanquez ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published diff --git a/src/vcard.py b/src/vcard.py index a6de9d244..dc1518658 100644 --- a/src/vcard.py +++ b/src/vcard.py @@ -194,7 +194,7 @@ class VcardWindow: gtk.STOCK_OPEN, gtk.RESPONSE_OK)) try: if os.name == 'nt': - path = os.environ['USERPROFILE'] + path = helpers.get_my_pictures_path() else: path = os.environ['HOME'] except: