1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-22 14:41:39 +00:00

Refactoring: Created hscommon.desktop

This unit hosts previously awkward UI view methods which weren't related
to the view itself, but to the current desktop environment. These
functions are now at their appropriate place.
This commit is contained in:
Virgil Dupras
2013-10-12 13:54:13 -04:00
parent 2fdfacb34e
commit 33d9569427
10 changed files with 92 additions and 50 deletions

67
hscommon/desktop.py Normal file
View File

@@ -0,0 +1,67 @@
# Created By: Virgil Dupras
# Created On: 2013-10-12
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
#
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
class SpecialFolder:
AppData = 1
Cache = 2
def open_url(url):
"""Open ``url`` with the default browser.
"""
_open_url(url)
def open_path(path):
"""Open ``path`` with its associated application.
"""
_open_path(str(path))
def reveal_path(path):
"""Open the folder containing ``path`` with the default file browser.
"""
_reveal_path(str(path))
def special_folder_path(special_folder):
"""Returns the path of ``special_folder``.
``special_folder`` is a SpecialFolder.* const.
"""
return _special_folder_path(special_folder)
try:
from cocoa import proxy
_open_url = proxy.openURL_
_open_path = proxy.openPath_
_reveal_path = proxy.revealPath_
def _special_folder_path(special_folder):
if special_folder == SpecialFolder.Cache:
return proxy.getCachePath()
else:
return proxy.getAppdataPath()
except ImportError:
try:
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QDesktopServices
import os.path as op
def _open_path(path):
url = QUrl.fromLocalFile(str(path))
QDesktopServices.openUrl(url)
def _reveal_path(path):
_open_path(op.dirname(str(path)))
def _special_folder_path(special_folder):
if special_folder == SpecialFolder.Cache:
qtfolder = QDesktopServices.CacheLocation
else:
qtfolder = QDesktopServices.DataLocation
return str(QDesktopServices.storageLocation(qtfolder))
except ImportError:
raise Exception("Can't setup desktop functions!")

View File

@@ -9,6 +9,7 @@
import re
from hashlib import md5
from . import desktop
from .trans import trget
tr = trget('hscommon')
@@ -47,7 +48,6 @@ class RegistrableApplication:
# setup_as_registered()
# show_message(msg)
# show_demo_nag(prompt)
# open_url(url)
PROMPT_NAME = "<undefined>"
DEMO_LIMITATION = "<undefined>"
@@ -154,13 +154,13 @@ class RegistrableApplication:
pass
def contribute(self):
self.view.open_url("http://open.hardcoded.net/contribute/")
desktop.open_url("http://open.hardcoded.net/contribute/")
def buy(self):
self.view.open_url("http://www.hardcoded.net/purchase.htm")
desktop.open_url("http://www.hardcoded.net/purchase.htm")
def about_fairware(self):
self.view.open_url("http://open.hardcoded.net/about/")
desktop.open_url("http://open.hardcoded.net/about/")
@property
def should_show_fairware_reminder(self):