| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Ayatana Webmail, the Preferences Dialog |
| 4 |
# Authors: Dmitry Shachnev <[email protected]> |
| 5 |
# Robert Tari <[email protected]> |
| 6 |
# License: GNU GPL 3 or higher; http://www.gnu.org/licenses/gpl.html |
| 7 |
|
| 8 |
import ayatanawebmail.imaplib2 as imaplib |
| 9 |
import os.path |
| 10 |
from socket import error as socketerror |
| 11 |
from gi.repository import Gtk, GdkPixbuf, Gdk |
| 12 |
from ayatanawebmail.common import g_oSettings, getDataPath |
| 13 |
from ayatanawebmail.appdata import APPVERSION, APPURL, APPDESCRIPTION, APPAUTHOR, APPYEAR, APPTITLE |
| 14 |
import webbrowser |
| 15 |
|
| 16 |
MESSAGEACTION = {'OPEN': 1, 'MARK': 2, 'ASK': 3} |
| 17 |
SERVERS = [_('Custom') + '\timap.example.com\t993\thttps://mail.example.com\thttps://mail.example.com/compose\thttps://mail.example.com/sent\thttps://mail.example.com/inbox\t/$MSG_UID', 'GMX\timap.gmx.net\t993\thttps://bap.navigator.gmx.net\thttps://bap.navigator.gmx.net\thttps://bap.navigator.gmx.net\thttps://bap.navigator.gmx.net\t/', 'Google\timap.gmail.com\t993\thttps://mail.google.com/mail/\thttps://mail.google.com/mail/#compose\thttps://mail.google.com/mail/#sent\thttps://mail.google.com/mail/#inbox\t/$MSG_THREAD', 'Horde\tmail.example.com\t993\thttps://mail.example.com/mailxchange/imp/dynamic.php?page=mailbox\thttps://mail.example.com/mailxchange/imp/dynamic.php?page=compose\thttps://mail.example.com/mailxchange/imp/dynamic.php?page=mailbox\thttps://mail.example.com/mailxchange/imp/dynamic.php?page=mailbox\t#msg:;$MSG_UID', 'RoundCube\tmail.example.com\t993\thttps://mail.example.com/?_task=mail&_mbox=INBOX\thttps://mail.example.com/?_task=mail&_action=compose\thttps://mail.example.com/?_task=mail&_mbox=Sent\thttps://mail.example.com/?_task=mail&_mbox=INBOX\t&_uid=$MSG_UID'] |
| 18 |
|
| 19 |
def utf7dec(lstInput): |
| 20 |
|
| 21 |
if not isinstance(lstInput, bytes): |
| 22 |
|
| 23 |
return lstInput |
| 24 |
|
| 25 |
lstResult = [] |
| 26 |
lstBytes = bytearray() |
| 27 |
|
| 28 |
for nChar in lstInput: |
| 29 |
|
| 30 |
if nChar == b'&'[0] and not lstBytes: |
| 31 |
|
| 32 |
lstBytes.append(nChar) |
| 33 |
|
| 34 |
elif nChar == b'-'[0] and lstBytes: |
| 35 |
|
| 36 |
if len(lstBytes) == 1: |
| 37 |
lstResult.append('&') |
| 38 |
else: |
| 39 |
lstResult.append((b'+' + lstBytes[1:].replace(b',', b'/') + b'-').decode('utf-7')) |
| 40 |
|
| 41 |
lstBytes = bytearray() |
| 42 |
|
| 43 |
elif lstBytes: |
| 44 |
|
| 45 |
lstBytes.append(nChar) |
| 46 |
|
| 47 |
else: |
| 48 |
|
| 49 |
lstResult.append(chr(nChar)) |
| 50 |
|
| 51 |
if lstBytes: |
| 52 |
lstResult.append((b'+' + lstBytes[1:].replace(b',', b'/') + b'-').decode('utf-7')) |
| 53 |
|
| 54 |
return ''.join(lstResult) |
| 55 |
|
| 56 |
class Entry(Gtk.Entry): |
| 57 |
|
| 58 |
def __init__(self, strId, **kwargs): |
| 59 |
|
| 60 |
Gtk.Entry.__init__(self, **kwargs) |
| 61 |
self.set_tooltip_text(_('If this string starts with http:// or https://, the application will open it in your browser - otherwise, it will be run as a command')) |
| 62 |
|
| 63 |
def setText(self, strText): |
| 64 |
|
| 65 |
if strText.startswith('Exec:'): |
| 66 |
|
| 67 |
strText = strText[5:] |
| 68 |
|
| 69 |
self.set_text(strText) |
| 70 |
|
| 71 |
def getText(self): |
| 72 |
|
| 73 |
strText = self.get_text() |
| 74 |
|
| 75 |
if not strText.startswith('http://') and not strText.startswith('https://'): |
| 76 |
|
| 77 |
strText = 'Exec:' + strText |
| 78 |
|
| 79 |
return strText |
| 80 |
|
| 81 |
class FileChooserButtonEx(Gtk.ButtonBox): |
| 82 |
|
| 83 |
def __init__(self, strFilename, **kwargs): |
| 84 |
|
| 85 |
Gtk.ButtonBox.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, layout_style=Gtk.ButtonBoxStyle.EXPAND, **kwargs) |
| 86 |
|
| 87 |
oButtonClear = Gtk.Button.new_from_icon_name('gtk-clear', Gtk.IconSize.BUTTON) |
| 88 |
oButtonClear.connect('clicked', self.onClear) |
| 89 |
oButtonOpen = Gtk.Button() |
| 90 |
oButtonOpen.connect('clicked', self.onOpen) |
| 91 |
self.oLabel = Gtk.Label(os.path.basename(strFilename) or _('(None)'), xalign=0, margin_left=5) |
| 92 |
oImage = Gtk.Image.new_from_icon_name('gtk-open', Gtk.IconSize.BUTTON) |
| 93 |
oBox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) |
| 94 |
oBox.pack_start(oImage, False, False, 0) |
| 95 |
oBox.pack_start(self.oLabel, True, True, 0) |
| 96 |
oButtonOpen.add(oBox) |
| 97 |
self.pack_start(oButtonOpen, True, True, 0) |
| 98 |
self.pack_start(oButtonClear, False, False, 0) |
| 99 |
self.set_homogeneous(False) |
| 100 |
self.strFilename = strFilename |
| 101 |
|
| 102 |
def onClear(self, oWidget): |
| 103 |
|
| 104 |
self.strFilename = '' |
| 105 |
self.oLabel.set_text(_('(None)')) |
| 106 |
|
| 107 |
def onOpen(self, oWidget): |
| 108 |
|
| 109 |
oDlg = Gtk.FileChooserDialog(None, oWidget.get_toplevel(), 0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.APPLY)) |
| 110 |
|
| 111 |
if self.strFilename: |
| 112 |
oDlg.set_filename(self.strFilename) |
| 113 |
|
| 114 |
nResponse = oDlg.run() |
| 115 |
|
| 116 |
if nResponse == Gtk.ResponseType.APPLY: |
| 117 |
|
| 118 |
self.strFilename = oDlg.get_filename() |
| 119 |
self.oLabel.set_text(os.path.basename(self.strFilename)) |
| 120 |
|
| 121 |
oDlg.destroy() |
| 122 |
|
| 123 |
def getFilename(self): |
| 124 |
|
| 125 |
return self.strFilename |
| 126 |
|
| 127 |
class PreferencesDialog(Gtk.Dialog): |
| 128 |
|
| 129 |
def __init__(self): |
| 130 |
|
| 131 |
self.bInit = False |
| 132 |
self.initConfig() |
| 133 |
Gtk.Dialog.__init__(self, _('Ayatana Webmail Preferences'), None, 0, (Gtk.STOCK_CONNECT, 100, Gtk.STOCK_APPLY, Gtk.ResponseType.APPLY, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) |
| 134 |
self.set_icon_name('ayatana-webmail') |
| 135 |
self.connect('destroy', lambda w: Gtk.main_quit()) |
| 136 |
self.connect('response', self.onResponse) |
| 137 |
self.set_position(Gtk.WindowPosition.CENTER) |
| 138 |
self.set_property('width-request', 640) |
| 139 |
self.set_property('height-request', 480) |
| 140 |
self.oNotebook = Gtk.Notebook(vexpand=True, margin_left=5, margin_top=5, margin_right=5, margin_bottom=5) |
| 141 |
self.oNotebook.append_page(self.pageAccounts(), Gtk.Label(_('Accounts'))) |
| 142 |
self.oNotebook.append_page(self.pageOptions(), Gtk.Label(_('Options'))) |
| 143 |
self.oNotebook.append_page(self.pageSupport(), Gtk.Label(_('Support'))) |
| 144 |
self.oNotebook.append_page(self.pageAbout(), Gtk.Label(_('About'))) |
| 145 |
oContentArea = self.get_content_area() |
| 146 |
oContentArea.set_property('vexpand', True) |
| 147 |
oContentArea.add(self.oNotebook) |
| 148 |
self.oButtonConnect = self.get_widget_for_response(100) |
| 149 |
self.oButtonApply = self.get_widget_for_response(Gtk.ResponseType.APPLY) |
| 150 |
self.lstDicts = [{'Host': self.lServers[0]['host'], 'Port': self.lServers[0]['port'], 'Login': '', 'Passwd': '', 'Folders': 'INBOX', 'InboxAppend': self.lServers[0]['message'], 'Home': self.lServers[0]['home'], 'Compose': self.lServers[0]['compose'], 'Inbox': self.lServers[0]['inbox'], 'Sent': self.lServers[0]['sent']}] |
| 151 |
self.set_keep_above(True) |
| 152 |
self.show_all() |
| 153 |
self.bInit = True |
| 154 |
self.nIndex = 0 |
| 155 |
self.bIgnoreServerChange = False |
| 156 |
|
| 157 |
def onResponse(self, oWidget, nResponse): |
| 158 |
|
| 159 |
if nResponse == 100: |
| 160 |
|
| 161 |
self.oNotebook.set_current_page(0) |
| 162 |
self.oListStore.clear() |
| 163 |
self.getFolderList(True) |
| 164 |
self.updateUI() |
| 165 |
|
| 166 |
def getFolderList(self, bAutoselect): |
| 167 |
|
| 168 |
try: |
| 169 |
|
| 170 |
oImap = None |
| 171 |
|
| 172 |
try: |
| 173 |
|
| 174 |
oImap = imaplib.IMAP4_SSL(self.EntryHost.get_text(), int(self.EntryPort.get_text())) |
| 175 |
|
| 176 |
except Exception: |
| 177 |
|
| 178 |
oImap = imaplib.IMAP4(self.EntryHost.get_text(), int(self.EntryPort.get_text())) |
| 179 |
oImap.starttls() |
| 180 |
|
| 181 |
oImap.login(self.EntryLogin.get_text(), self.EntryPassword.get_text()) |
| 182 |
|
| 183 |
for f in oImap.list()[1]: |
| 184 |
|
| 185 |
flags, b, c = utf7dec(f).partition(' ') |
| 186 |
separator, b, strName = c.partition(' ') |
| 187 |
strName = strName.replace('"', '').replace('/ ', '') |
| 188 |
|
| 189 |
if strName != '[Gmail]' and 'All Mail' not in strName: |
| 190 |
self.oListStore.append([strName, strName.replace('[Gmail]/', ''), strName.upper() == 'INBOX' if bAutoselect else False]) |
| 191 |
|
| 192 |
oImap.logout() |
| 193 |
|
| 194 |
except (imaplib.IMAP4.error, socketerror) as oError: |
| 195 |
|
| 196 |
oDlg = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, '') |
| 197 |
|
| 198 |
strError = str(oError) |
| 199 |
|
| 200 |
if strError.startswith("b'"): |
| 201 |
strError = strError[1:] |
| 202 |
|
| 203 |
oDlg.set_property('text', _('Failed to connect to mail account. The returned error was:') + '\n\n' + strError) |
| 204 |
oDlg.set_title(_('Connection failure')) |
| 205 |
oDlg.run() |
| 206 |
oDlg.destroy() |
| 207 |
|
| 208 |
def initConfig(self): |
| 209 |
|
| 210 |
self.bEnableNotifications = g_oSettings.get_boolean('enable-notifications') |
| 211 |
self.bPlaySound = g_oSettings.get_boolean('enable-sound') |
| 212 |
self.bHideCount = g_oSettings.get_boolean('hide-messages-count') |
| 213 |
self.strCommand = g_oSettings.get_string('exec-on-receive') |
| 214 |
self.strCustomSound = g_oSettings.get_string('custom-sound') |
| 215 |
self.bMergeConversation = g_oSettings.get_boolean('merge-messages') |
| 216 |
self.nMessageAction = g_oSettings.get_enum('message-action') |
| 217 |
self.lServers = [] |
| 218 |
|
| 219 |
for sServer in SERVERS: |
| 220 |
|
| 221 |
lValues = sServer.split('\t') |
| 222 |
lValues.append('\t'.join(lValues[1:])) |
| 223 |
dServer = dict(zip(['name', 'host', 'port', 'home', 'compose', 'sent', 'inbox', 'message', 'raw'], lValues)) |
| 224 |
self.lServers.append(dServer) |
| 225 |
|
| 226 |
def pageAccounts(self): |
| 227 |
|
| 228 |
self.sb = Gtk.SpinButton.new_with_range(1, 1, 1) |
| 229 |
self.sb.set_numeric(True) |
| 230 |
self.sb.set_update_policy(Gtk.SpinButtonUpdatePolicy.IF_VALID) |
| 231 |
self.sb.connect('value-changed', self.onAccountChanged) |
| 232 |
self.addbtn = Gtk.Button.new_with_label(_('Add')) |
| 233 |
self.addbtn.connect('clicked', self.onAddAccount) |
| 234 |
self.rmbtn = Gtk.Button.new_with_label(_('Remove')) |
| 235 |
self.rmbtn.connect('clicked', self.onRemoveAccount) |
| 236 |
accbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5, hexpand=True) |
| 237 |
accbox.pack_start(self.sb, True, True, 0) |
| 238 |
accbox.pack_end(self.rmbtn, False, False, 0) |
| 239 |
accbox.pack_end(self.addbtn, False, False, 0) |
| 240 |
self.pComboBoxTextServer = Gtk.ComboBoxText() |
| 241 |
self.pComboBoxTextServer.connect('changed', self.onComboBoxTextServerChanged) |
| 242 |
|
| 243 |
for dServer in self.lServers: |
| 244 |
|
| 245 |
self.pComboBoxTextServer.append(None, dServer['name']) |
| 246 |
|
| 247 |
self.pComboBoxTextServer.set_active_id('custom') |
| 248 |
self.EntryHost = Gtk.Entry(hexpand=True) |
| 249 |
self.EntryHost.connect('changed', lambda w: self.updateUI()) |
| 250 |
self.EntryPort = Gtk.Entry(hexpand=True) |
| 251 |
self.EntryPort.connect('changed', lambda w: self.updateUI()) |
| 252 |
self.EntryLogin = Gtk.Entry(hexpand=True) |
| 253 |
self.EntryLogin.connect('changed', lambda w: self.updateUI()) |
| 254 |
self.EntryPassword = Gtk.Entry(visibility=False, caps_lock_warning=True, hexpand=True) |
| 255 |
self.EntryPassword.connect('changed', lambda w: self.updateUI()) |
| 256 |
self.oListStore = Gtk.ListStore(str, str, bool) |
| 257 |
oTreeView = Gtk.TreeView(self.oListStore, headers_visible=False, activate_on_single_click=True, margin_left=5, margin_top=5, margin_right=5, margin_bottom=5) |
| 258 |
oTreeView.connect('row-activated', self.onFolderActivated) |
| 259 |
oTreeViewColumnBool = Gtk.TreeViewColumn('bool', Gtk.CellRendererToggle(), active=2) |
| 260 |
oTreeViewColumnBool.get_cells()[0].set_property('xalign', 1.0) |
| 261 |
oTreeView.append_column(Gtk.TreeViewColumn('folder', Gtk.CellRendererText(), text=1)) |
| 262 |
oTreeView.append_column(oTreeViewColumnBool) |
| 263 |
oFrame = Gtk.ScrolledWindow(shadow_type=Gtk.ShadowType.IN, hexpand=True, vexpand=True) |
| 264 |
oFrame.set_property('height-request', 200) |
| 265 |
oFrame.add(oTreeView) |
| 266 |
self.oEntryHome = Entry('Home', hexpand=True) |
| 267 |
self.oEntryHome.connect('changed', lambda w: self.updateUI()) |
| 268 |
self.oEntryCompose = Entry('Compose', hexpand=True) |
| 269 |
self.oEntryCompose.connect('changed', lambda w: self.updateUI()) |
| 270 |
self.oEntryInbox = Entry('Inbox', hexpand=True) |
| 271 |
self.oEntryInbox.connect('changed', lambda w: self.updateUI()) |
| 272 |
self.oEntrySent = Entry('Sent', hexpand=True) |
| 273 |
self.oEntrySent.connect('changed', lambda w: self.updateUI()) |
| 274 |
self.oEntryInboxAppend = Gtk.Entry(hexpand=True) |
| 275 |
self.oEntryInboxAppend.connect('changed', lambda w: self.updateUI()) |
| 276 |
self.oEntryInboxAppend.set_tooltip_text(_('The application will append this string to "Inbox" to access a specific message - you can use the $MSG_THREAD and $MSG_UID placeholders')) |
| 277 |
oGrid = Gtk.Grid(row_spacing=5, column_spacing=5, vexpand=True) |
| 278 |
oGrid.attach(Gtk.Label(_('Account:'), xalign=0, margin_right=5), 0, 0, 1, 1) |
| 279 |
oGrid.attach(accbox, 1, 0, 1, 1) |
| 280 |
oGrid.attach(Gtk.Label(_('Server:'), xalign=0, margin_right=5), 0, 1, 1, 1) |
| 281 |
oGrid.attach(self.pComboBoxTextServer, 1, 1, 1, 1) |
| 282 |
oGrid.attach(Gtk.Label(_('Host:'), xalign=0, margin_right=5), 0, 2, 1, 1) |
| 283 |
oGrid.attach(self.EntryHost, 1, 2, 1, 1) |
| 284 |
oGrid.attach(Gtk.Label(_('Port:'), xalign=0, margin_right=5), 0, 3, 1, 1) |
| 285 |
oGrid.attach(self.EntryPort, 1, 3, 1, 1) |
| 286 |
oGrid.attach(Gtk.Label(_('Username:'), xalign=0, margin_right=5), 0, 4, 1, 1) |
| 287 |
oGrid.attach(self.EntryLogin, 1, 4, 1, 1) |
| 288 |
oGrid.attach(Gtk.Label(_('Password:'), xalign=0, margin_right=5), 0, 5, 1, 1) |
| 289 |
oGrid.attach(self.EntryPassword, 1, 5, 1, 1) |
| 290 |
oGrid.attach(Gtk.Label(_('Folders:'), xalign=0, margin_right=5), 0, 6, 1, 1) |
| 291 |
oGrid.attach(oFrame, 1, 6, 1, 1) |
| 292 |
oGrid.attach(Gtk.Label(_('Home:'), xalign=0, margin_right=5), 0, 7, 1, 1) |
| 293 |
oGrid.attach(self.oEntryHome, 1, 7, 1, 1) |
| 294 |
oGrid.attach(Gtk.Label(_('Compose:'), xalign=0, margin_right=5), 0, 8, 1, 1) |
| 295 |
oGrid.attach(self.oEntryCompose, 1, 8, 1, 1) |
| 296 |
oGrid.attach(Gtk.Label(_('Sent:'), xalign=0, margin_right=5), 0, 9, 1, 1) |
| 297 |
oGrid.attach(self.oEntrySent, 1, 9, 1, 1) |
| 298 |
oGrid.attach(Gtk.Label(_('Inbox:'), xalign=0, margin_right=5), 0, 10, 1, 1) |
| 299 |
oGrid.attach(self.oEntryInbox, 1, 10, 1, 1) |
| 300 |
oGrid.attach(Gtk.Label(_('Message:'), xalign=0, margin_right=5), 0, 11, 1, 1) |
| 301 |
oGrid.attach(self.oEntryInboxAppend, 1, 11, 1, 1) |
| 302 |
page = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5, border_width=10, vexpand=True) |
| 303 |
page.add(oGrid) |
| 304 |
oScrolledWindow = Gtk.ScrolledWindow() |
| 305 |
oScrolledWindow.add(page) |
| 306 |
|
| 307 |
nHeight = 721 |
| 308 |
oDisplay = Gdk.Display.get_default() |
| 309 |
|
| 310 |
if oDisplay: |
| 311 |
|
| 312 |
oMonitor = None |
| 313 |
|
| 314 |
# get_primary_monitor is available in >= 3.22 |
| 315 |
try: |
| 316 |
oMonitor = oDisplay.get_primary_monitor() |
| 317 |
except Exception as oException: |
| 318 |
pass |
| 319 |
|
| 320 |
if oMonitor: |
| 321 |
nHeight = oMonitor.get_workarea().height |
| 322 |
|
| 323 |
if nHeight > 720: |
| 324 |
|
| 325 |
# propagate_natural_height is available in >= 3.22 |
| 326 |
try: |
| 327 |
oScrolledWindow.props.propagate_natural_height = True |
| 328 |
except Exception as oException: |
| 329 |
pass |
| 330 |
|
| 331 |
return oScrolledWindow |
| 332 |
|
| 333 |
def pageOptions(self): |
| 334 |
|
| 335 |
self.oComboMessageAction = Gtk.ComboBoxText() |
| 336 |
self.oComboMessageAction.append(str(MESSAGEACTION['MARK']), _('Mark message as read')) |
| 337 |
self.oComboMessageAction.append(str(MESSAGEACTION['OPEN']), _('Open message in browser/Execute command')) |
| 338 |
self.oComboMessageAction.append(str(MESSAGEACTION['ASK']), _('Ask me what to do')) |
| 339 |
self.oComboMessageAction.set_active_id(str(self.nMessageAction)) |
| 340 |
self.oSwitchMerge = Gtk.Switch(active=self.bMergeConversation, halign=Gtk.Align.END) |
| 341 |
self.notifyswitch = Gtk.Switch(active=self.bEnableNotifications, halign=Gtk.Align.END) |
| 342 |
self.sndswitch = Gtk.Switch(active=self.bPlaySound, halign=Gtk.Align.END) |
| 343 |
self.sndswitch.connect('notify::active', self.onSoundSwitchActivate) |
| 344 |
self.hcswitch = Gtk.Switch(active=self.bHideCount, halign=Gtk.Align.END) |
| 345 |
self.commandchooser = FileChooserButtonEx(self.strCommand) |
| 346 |
self.sndchooser = FileChooserButtonEx(self.strCustomSound) |
| 347 |
oGrid = Gtk.Grid(row_spacing=5, column_spacing=10) |
| 348 |
oGrid.attach(Gtk.Label(_('Enable notifications:'), xalign=0), 0, 0, 1, 1) |
| 349 |
oGrid.attach(self.notifyswitch, 1, 0, 1, 1) |
| 350 |
oGrid.attach(Gtk.Label(_('Play sound when a message is received:'), xalign=0), 0, 1, 1, 1) |
| 351 |
oGrid.attach(self.sndswitch, 1, 1, 1, 1) |
| 352 |
oGrid.attach(Gtk.Label(_('Merge messages from the same conversation:'), xalign=0), 0, 2, 1, 1) |
| 353 |
oGrid.attach(self.oSwitchMerge, 1, 2, 1, 1) |
| 354 |
oGrid.attach(Gtk.Label(_('Hide count when zero:'), xalign=0), 0, 3, 1, 1) |
| 355 |
oGrid.attach(self.hcswitch, 1, 3, 1, 1) |
| 356 |
oGrid.attach(Gtk.Label(_('When a message is activated:'), xalign=0), 0, 4, 1, 1) |
| 357 |
oGrid.attach(self.oComboMessageAction, 1, 4, 1, 1) |
| 358 |
commandbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10) |
| 359 |
commandbox.add(Gtk.Label(_('Execute this command when a message is received:'), xalign=0)) |
| 360 |
commandbox.pack_end(self.commandchooser, True, True, 0) |
| 361 |
commandbox.set_tooltip_text (_('If a command is set, it will be called with the following parameters: sender, subject, IMAP host')) |
| 362 |
|
| 363 |
if self.commandchooser.get_allocated_width() < 180: |
| 364 |
self.commandchooser.set_size_request(180, 0) |
| 365 |
|
| 366 |
self.sndbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10, sensitive=self.bPlaySound) |
| 367 |
self.sndbox.add(Gtk.Label(_('Custom sound to play:'), xalign=0)) |
| 368 |
self.sndbox.pack_end(self.sndchooser, True, True, 0) |
| 369 |
|
| 370 |
if self.sndchooser.get_allocated_width() < 180: |
| 371 |
self.sndchooser.set_size_request(180, 0) |
| 372 |
|
| 373 |
page = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5, border_width=10) |
| 374 |
page.add(oGrid) |
| 375 |
page.add(commandbox) |
| 376 |
page.add(self.sndbox) |
| 377 |
|
| 378 |
return page |
| 379 |
|
| 380 |
def pageSupport(self): |
| 381 |
|
| 382 |
oGrid = Gtk.Grid(border_width=10, row_spacing=2) |
| 383 |
oGrid.attach(Gtk.Label(_('Report a bug'), xalign=0), 0, 0, 1, 1) |
| 384 |
oGrid.attach(Gtk.Label('<a href="https://github.com/AyatanaIndicators/ayatana-webmail/issues">https://github.com/AyatanaIndicators/ayatana-webmail/issues</a>', xalign=0, use_markup=True, margin_bottom=10), 0, 1, 1, 1) |
| 385 |
oGrid.attach(Gtk.Label(_('Request a feature'), xalign=0), 0, 2, 1, 1) |
| 386 |
oGrid.attach(Gtk.Label('<a href="https://github.com/AyatanaIndicators/ayatana-webmail/issues">https://github.com/AyatanaIndicators/ayatana-webmail/issues</a>', xalign=0, use_markup=True), 0, 3, 1, 1) |
| 387 |
oGrid.attach(Gtk.Label(_('It\'s a good idea to add the {labelname} label to your issue.').format(labelname='<b>enhancement</b>'), xalign=0, margin_bottom=10, use_markup=True), 0, 4, 1, 1) |
| 388 |
oGrid.attach(Gtk.Label(_('Ask a question'), xalign=0), 0, 5, 1, 1) |
| 389 |
oGrid.attach(Gtk.Label('<a href="https://github.com/AyatanaIndicators/ayatana-webmail/issues">https://github.com/AyatanaIndicators/ayatana-webmail/issues</a>', xalign=0, use_markup=True), 0, 6, 1, 1) |
| 390 |
oGrid.attach(Gtk.Label(_('It\'s a good idea to add the {labelname} label to your issue.').format(labelname='<b>question</b>'), xalign=0, margin_bottom=10, use_markup=True), 0, 7, 1, 1) |
| 391 |
oGrid.attach(Gtk.Label(_('Help translate'), xalign=0), 0, 8, 1, 1) |
| 392 |
oGrid.attach(Gtk.Label('<a href="https://hosted.weblate.org/projects/ayatana-indicators/ayatana-webmail/">https://hosted.weblate.org/projects/ayatana-indicators/ayatana-webmail/</a>', xalign=0, use_markup=True, margin_bottom=10), 0, 9, 1, 1) |
| 393 |
oGrid.attach(Gtk.Label(_('Source code'), xalign=0), 0, 10, 1, 1) |
| 394 |
oGrid.attach(Gtk.Label('<a href="https://github.com/AyatanaIndicators/ayatana-webmail">https://github.com/AyatanaIndicators/ayatana-webmail</a>', xalign=0, use_markup=True, margin_bottom=10), 0, 11, 1, 1) |
| 395 |
oGrid.attach(Gtk.Label(_('Home page'), xalign=0), 0, 12, 1, 1) |
| 396 |
oGrid.attach(Gtk.Label('<a href="https://tari.in/www/software/ayatana-webmail/">https://tari.in/www/software/ayatana-webmail/</a>', xalign=0, use_markup=True, margin_bottom=10), 0, 13, 1, 1) |
| 397 |
|
| 398 |
return oGrid |
| 399 |
|
| 400 |
def onActivateLinkAbout(self, pAboutDialog, sUrl): |
| 401 |
|
| 402 |
webbrowser.open_new_tab(sUrl) |
| 403 |
|
| 404 |
return True |
| 405 |
|
| 406 |
def pageAbout(self): |
| 407 |
|
| 408 |
oBox = Gtk.Box() |
| 409 |
oAboutDialog = Gtk.AboutDialog() |
| 410 |
oAboutDialog.set_license_type(Gtk.License.GPL_3_0) |
| 411 |
oAboutDialog.set_program_name(APPTITLE) |
| 412 |
oAboutDialog.set_copyright(APPAUTHOR + ' ' + (APPYEAR if APPYEAR[-2:] == APPVERSION[:2] else APPYEAR + '-20' + APPVERSION[:2])) |
| 413 |
oAboutDialog.set_comments(_(APPDESCRIPTION)) |
| 414 |
oAboutDialog.set_authors(['Robert Tari <[email protected]>']) |
| 415 |
oAboutDialog.set_translator_credits(_('translator-credits')) |
| 416 |
oAboutDialog.set_version(APPVERSION) |
| 417 |
oAboutDialog.set_website(APPURL) |
| 418 |
oAboutDialog.set_website_label(APPURL) |
| 419 |
oAboutDialog.set_logo(GdkPixbuf.Pixbuf().new_from_file(getDataPath('/usr/share/icons/hicolor/scalable/apps/ayatanawebmail.svg'))) |
| 420 |
oAboutDialog.get_content_area().reparent(oBox) |
| 421 |
oAboutDialog.get_content_area().set_hexpand(True) |
| 422 |
oAboutDialog.connect('activate_link', self.onActivateLinkAbout) |
| 423 |
|
| 424 |
lstChildren = oAboutDialog.action_area.get_children() |
| 425 |
|
| 426 |
for oWidget in lstChildren: |
| 427 |
|
| 428 |
if (isinstance(oWidget, Gtk.Button) and not isinstance(oWidget, Gtk.ToggleButton)) or (isinstance(oWidget, Gtk.ToggleButton) and len(lstChildren) == 3 and oWidget == lstChildren[1]): |
| 429 |
|
| 430 |
oWidget.set_property('no-show-all', True) |
| 431 |
oWidget.set_property('visible', False) |
| 432 |
|
| 433 |
return oBox |
| 434 |
|
| 435 |
def onFolderActivated(self, oView, nRow, oColumn): |
| 436 |
|
| 437 |
self.oListStore[nRow][2] = not self.oListStore[nRow][2] |
| 438 |
self.updateUI() |
| 439 |
|
| 440 |
def updateUI(self): |
| 441 |
|
| 442 |
bHasFolderSelection = [oRow for oRow in self.oListStore if oRow[2]] |
| 443 |
bHasAccountData = all([oWidget.get_text() for oWidget in [self.EntryHost, self.EntryPort, self.EntryLogin, self.EntryPassword]]) |
| 444 |
bHasMultipleAccounts = len(self.lstDicts) > 1 |
| 445 |
bHasLinkData = all([oWidget.get_text() for oWidget in [self.oEntryHome, self.oEntryCompose, self.oEntryInbox, self.oEntrySent, self.oEntryInboxAppend]]) |
| 446 |
|
| 447 |
self.oButtonConnect.set_sensitive(bHasAccountData) |
| 448 |
self.oButtonApply.set_sensitive(bHasFolderSelection and bHasAccountData and bHasLinkData) |
| 449 |
self.rmbtn.set_sensitive(bHasMultipleAccounts) |
| 450 |
self.addbtn.set_sensitive(bHasFolderSelection and bHasAccountData and bHasLinkData) |
| 451 |
self.sb.set_sensitive(bHasFolderSelection and bHasAccountData and bHasMultipleAccounts and bHasLinkData) |
| 452 |
|
| 453 |
nServerActive = 0 |
| 454 |
|
| 455 |
for nServer, dServer in enumerate(self.lServers): |
| 456 |
|
| 457 |
if dServer['raw'] == self.EntryHost.get_text() + '\t' + self.EntryPort.get_text() + '\t' + self.oEntryHome.get_text() + '\t' + self.oEntryCompose.get_text() + '\t' + self.oEntrySent.get_text() + '\t' + self.oEntryInbox.get_text() + '\t' + self.oEntryInboxAppend.get_text(): |
| 458 |
|
| 459 |
nServerActive = nServer |
| 460 |
|
| 461 |
break |
| 462 |
|
| 463 |
if self.pComboBoxTextServer.get_active() != nServerActive: |
| 464 |
|
| 465 |
self.bIgnoreServerChange = True |
| 466 |
self.pComboBoxTextServer.set_active(nServerActive) |
| 467 |
self.bIgnoreServerChange = False |
| 468 |
|
| 469 |
def run(self): |
| 470 |
|
| 471 |
if not self.lstDicts[0]['Passwd']: |
| 472 |
self.updateEntries() |
| 473 |
|
| 474 |
self.updateUI() |
| 475 |
Gtk.main() |
| 476 |
|
| 477 |
def saveAllSettings(self): |
| 478 |
|
| 479 |
g_oSettings.set_boolean('enable-notifications', self.notifyswitch.get_active()) |
| 480 |
g_oSettings.set_boolean('enable-sound', self.sndswitch.get_active()) |
| 481 |
g_oSettings.set_boolean('hide-messages-count', self.hcswitch.get_active()) |
| 482 |
g_oSettings.set_string('exec-on-receive', self.commandchooser.getFilename()) |
| 483 |
g_oSettings.set_string('custom-sound', self.sndchooser.getFilename()) |
| 484 |
g_oSettings.set_boolean('merge-messages', self.oSwitchMerge.get_active()) |
| 485 |
g_oSettings.set_enum('message-action', int(self.oComboMessageAction.get_active_id())) |
| 486 |
|
| 487 |
def onAddAccount(self, btn): |
| 488 |
|
| 489 |
self.updateAccounts() |
| 490 |
nServer = self.pComboBoxTextServer.get_active() |
| 491 |
self.lstDicts.append({'Host': self.lServers[nServer]['host'], 'Port': self.lServers[nServer]['port'], 'Login': '', 'Passwd': '', 'Folders': 'INBOX', 'InboxAppend': self.lServers[nServer]['message'], 'Home': self.lServers[nServer]['home'], 'Compose': self.lServers[nServer]['compose'], 'Inbox': self.lServers[nServer]['inbox'], 'Sent': self.lServers[nServer]['sent']}) |
| 492 |
self.sb.set_range(1, len(self.lstDicts)) |
| 493 |
self.sb.set_value(len(self.lstDicts)) |
| 494 |
self.updateUI() |
| 495 |
|
| 496 |
def onRemoveAccount(self, btn): |
| 497 |
|
| 498 |
self.updateAccounts() |
| 499 |
index = self.sb.get_value_as_int()-1 |
| 500 |
|
| 501 |
del self.lstDicts[index] |
| 502 |
|
| 503 |
self.bInit = False |
| 504 |
self.sb.set_range(1, len(self.lstDicts)) |
| 505 |
self.bInit = True |
| 506 |
self.updateEntries() |
| 507 |
self.updateUI() |
| 508 |
|
| 509 |
if index+1 > len(self.lstDicts): |
| 510 |
self.sb.set_value(index) |
| 511 |
|
| 512 |
self.updateUI() |
| 513 |
|
| 514 |
def setAccounts(self, lstDicts): |
| 515 |
|
| 516 |
self.bInit = False |
| 517 |
self.lstDicts = [dct for dct in lstDicts] |
| 518 |
self.nIndex = 0 |
| 519 |
self.sb.set_range(1, len(lstDicts)) |
| 520 |
self.updateEntries() |
| 521 |
self.updateUI() |
| 522 |
self.bInit = True |
| 523 |
|
| 524 |
def onAccountChanged(self, sb): |
| 525 |
|
| 526 |
self.updateAccounts() |
| 527 |
self.nIndex = self.sb.get_value_as_int() - 1 |
| 528 |
self.updateEntries() |
| 529 |
self.updateUI() |
| 530 |
|
| 531 |
def onSoundSwitchActivate(self, sndswitch, param): |
| 532 |
|
| 533 |
self.sndbox.set_sensitive(sndswitch.get_active()) |
| 534 |
|
| 535 |
def updateEntries(self): |
| 536 |
|
| 537 |
if self.lstDicts: |
| 538 |
|
| 539 |
nIndex = self.sb.get_value_as_int() - 1 |
| 540 |
self.EntryHost.set_text(self.lstDicts[nIndex]['Host']) |
| 541 |
self.EntryPort.set_text(str(self.lstDicts[nIndex]['Port'])) |
| 542 |
self.EntryLogin.set_text(self.lstDicts[nIndex]['Login']) |
| 543 |
self.EntryPassword.set_text(self.lstDicts[nIndex]['Passwd']) |
| 544 |
|
| 545 |
self.oListStore.clear() |
| 546 |
|
| 547 |
if self.lstDicts[nIndex]['Passwd']: |
| 548 |
|
| 549 |
self.getFolderList(False) |
| 550 |
|
| 551 |
lstFolders = self.lstDicts[nIndex]['Folders'].split('\t') |
| 552 |
|
| 553 |
for oRow in self.oListStore: |
| 554 |
oRow[2] = oRow[0] in lstFolders |
| 555 |
|
| 556 |
self.oEntryHome.setText(self.lstDicts[nIndex]['Home']) |
| 557 |
self.oEntryCompose.setText(self.lstDicts[nIndex]['Compose']) |
| 558 |
self.oEntryInbox.setText(self.lstDicts[nIndex]['Inbox']) |
| 559 |
self.oEntrySent.setText(self.lstDicts[nIndex]['Sent']) |
| 560 |
self.oEntryInboxAppend.set_text(self.lstDicts[nIndex]['InboxAppend']) |
| 561 |
|
| 562 |
nServerActive = 0 |
| 563 |
|
| 564 |
for nServer, dServer in enumerate(self.lServers): |
| 565 |
|
| 566 |
if dServer['raw'] == self.EntryHost.get_text() + '\t' + self.EntryPort.get_text() + '\t' + self.oEntryHome.get_text() + '\t' + self.oEntryCompose.get_text() + '\t' + self.oEntrySent.get_text() + '\t' + self.oEntryInbox.get_text() + '\t' + self.oEntryInboxAppend.get_text(): |
| 567 |
|
| 568 |
nServerActive = nServer |
| 569 |
|
| 570 |
break |
| 571 |
|
| 572 |
if self.pComboBoxTextServer.get_active() != nServerActive: |
| 573 |
|
| 574 |
self.bIgnoreServerChange = True |
| 575 |
self.pComboBoxTextServer.set_active(nServerActive) |
| 576 |
self.bIgnoreServerChange = False |
| 577 |
|
| 578 |
def onComboBoxTextServerChanged(self, pComboBoxText): |
| 579 |
|
| 580 |
if not self.bIgnoreServerChange: |
| 581 |
|
| 582 |
nServer = self.pComboBoxTextServer.get_active() |
| 583 |
|
| 584 |
if self.lServers[nServer]['raw'] != self.EntryHost.get_text() + '\t' + self.EntryPort.get_text() + '\t' + self.oEntryHome.get_text() + '\t' + self.oEntryCompose.get_text() + '\t' + self.oEntrySent.get_text() + '\t' + self.oEntryInbox.get_text() + '\t' + self.oEntryInboxAppend.get_text(): |
| 585 |
|
| 586 |
self.EntryHost.set_text(self.lServers[nServer]['host']) |
| 587 |
self.EntryPort.set_text(self.lServers[nServer]['port']) |
| 588 |
self.EntryLogin.set_text('') |
| 589 |
self.EntryPassword.set_text('') |
| 590 |
self.oListStore.clear() |
| 591 |
self.oEntryHome.setText(self.lServers[nServer]['home']) |
| 592 |
self.oEntryCompose.setText(self.lServers[nServer]['compose']) |
| 593 |
self.oEntryInbox.setText(self.lServers[nServer]['inbox']) |
| 594 |
self.oEntrySent.setText(self.lServers[nServer]['sent']) |
| 595 |
self.oEntryInboxAppend.set_text(self.lServers[nServer]['message']) |
| 596 |
|
| 597 |
def updateAccounts(self): |
| 598 |
|
| 599 |
if self.bInit: |
| 600 |
|
| 601 |
self.lstDicts[self.nIndex]['Host'] = self.EntryHost.get_text() |
| 602 |
|
| 603 |
if self.EntryPort.get_text(): |
| 604 |
self.lstDicts[self.nIndex]['Port'] = self.EntryPort.get_text() |
| 605 |
else: |
| 606 |
self.lstDicts[self.nIndex]['Port'] = '993' |
| 607 |
|
| 608 |
self.lstDicts[self.nIndex]['Login'] = self.EntryLogin.get_text() |
| 609 |
self.lstDicts[self.nIndex]['Passwd'] = self.EntryPassword.get_text() |
| 610 |
self.lstDicts[self.nIndex]['Folders'] = '\t'.join([oRow[0] for oRow in self.oListStore if oRow[2]]) |
| 611 |
self.lstDicts[self.nIndex]['Home'] = self.oEntryHome.getText() |
| 612 |
self.lstDicts[self.nIndex]['Compose'] = self.oEntryCompose.getText() |
| 613 |
self.lstDicts[self.nIndex]['Inbox'] = self.oEntryInbox.getText() |
| 614 |
self.lstDicts[self.nIndex]['Sent'] = self.oEntrySent.getText() |
| 615 |
self.lstDicts[self.nIndex]['InboxAppend'] = self.oEntryInboxAppend.get_text() |