aboutsummaryrefslogtreecommitdiff
path: root/ayatanawebmail/common.py
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2020-08-17 17:40:59 +0200
committerRobert Tari <robert@tari.in>2020-08-17 17:40:59 +0200
commit711050055339f6a14f0c3da4d3d28f707b97a102 (patch)
tree7c69fbc7809bc1592bab47c811c6d9e4ddf964da /ayatanawebmail/common.py
downloadayatana-webmail-711050055339f6a14f0c3da4d3d28f707b97a102.tar.gz
ayatana-webmail-711050055339f6a14f0c3da4d3d28f707b97a102.tar.bz2
ayatana-webmail-711050055339f6a14f0c3da4d3d28f707b97a102.zip
Initial port from Unity Mail
Diffstat (limited to 'ayatanawebmail/common.py')
-rwxr-xr-xayatanawebmail/common.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/ayatanawebmail/common.py b/ayatanawebmail/common.py
new file mode 100755
index 0000000..95d3797
--- /dev/null
+++ b/ayatanawebmail/common.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Ayatana Webmail, message actions dialog
+# Authors: Robert Tari <robert@tari.in>
+# License: GNU GPL 3 or higher; http://www.gnu.org/licenses/gpl.html
+
+import gettext
+import os
+import psutil
+import subprocess
+import webbrowser
+from gi.repository import Gio
+from ayatanawebmail.appdata import APPEXECUTABLE, APPNAME
+from ayatanawebmail.accounts import DialogAccounts
+
+try:
+ g_oTranslation = gettext.translation(APPNAME)
+except IOError:
+ g_oTranslation = gettext.NullTranslations()
+
+g_oTranslation.install()
+
+g_dctDefaultURLs = {'Home': 'https://mail.google.com/mail/', 'Compose': 'https://mail.google.com/mail/#compose', 'Inbox': 'https://mail.google.com/mail/#inbox', 'Sent': 'https://mail.google.com/mail/#sent'}
+g_oSettings = Gio.Settings.new('org.ayatana.webmail')
+g_lstAccounts = []
+
+def getDataPath(strPath):
+
+ try:
+
+ strExecPath = os.path.split(APPEXECUTABLE)[0]
+ strDataPath = os.getcwd().replace(strExecPath, '')
+ strRelativePath = os.path.join(strDataPath, strPath.lstrip('/'))
+
+ if os.path.exists(strRelativePath):
+ return strRelativePath
+
+ except:
+
+ pass
+
+ return strPath
+
+def isRunning():
+
+ nCount = 0
+
+ for oProc in psutil.process_iter():
+
+ strName = oProc.name
+
+ if not isinstance(strName, str):
+
+ strName = oProc.name()
+
+ if strName == 'python3' or strName == 'python':
+
+ lstCmdline = oProc.cmdline
+
+ if not isinstance(lstCmdline, list):
+ lstCmdline = oProc.cmdline()
+
+ for strCmd in lstCmdline:
+
+ if strCmd.endswith('ayatana-webmail'):
+ nCount += 1
+
+ elif strName.endswith('ayatana-webmail'):
+
+ nCount += 1
+
+ return nCount
+
+def resolveURL(strURL):
+
+ if strURL.startswith('Exec:'):
+ subprocess.Popen(strURL[5:], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
+ elif strURL.startswith('http'):
+ webbrowser.open_new_tab(strURL)
+
+def openURLOrCommand(strURL):
+
+ if strURL in g_dctDefaultURLs:
+
+ strURL0 = g_lstAccounts[0][strURL]
+
+ if len(g_lstAccounts) > 1:
+
+ for dctAccount in g_lstAccounts[1:]:
+
+ if dctAccount[strURL] != strURL0:
+
+ oDialogAccounts = DialogAccounts(strURL, getDataPath, g_lstAccounts)
+ oDialogAccounts.run()
+ strURL = oDialogAccounts.strURL
+ oDialogAccounts.destroy()
+
+ if strURL:
+ resolveURL(strURL)
+
+ return
+
+ resolveURL(strURL0)
+
+ elif strURL.startswith('Exec:') or strURL.startswith('http'):
+
+ resolveURL(strURL)
+
+ else:
+
+ print('Unknown URL name!')
+ print('Possible URL names: "Home", "Compose", "Inbox", "Sent", "Exec:...", "http..."')