updated on Thu Jan 12 08:01:00 UTC 2012
[aur-mirror.git] / mounty-xfce / mounty.py
blob3296b6652537cd0b47bde071676689cb325b2134
1 #!/usr/bin/python2
3 import os
4 import sys
5 import pynotify
6 import gtk
7 import locale
8 import gettext
9 from diskimage import DiskImage
10 #import appindicator
11 import time
12 import gconf
13 import shutil
14 import gio
16 APP = "mounty"
17 APP_VERSION = "0.1.3"
18 DIR = '/usr/share/locale/'
20 locale.setlocale(locale.LC_ALL, '')
21 gettext.bindtextdomain(APP, DIR)
22 gettext.textdomain(APP)
23 _ = gettext.gettext
25 # register to libnotify
26 if not pynotify.init("mounty"):
27 error(_("Cannot initialize libnotify"))
28 sys.exit(1)
30 class application:
31 def __init__(self):
32 # Begin XFCEpatch
33 # self.ind = appindicator.Indicator ("mounty", "mounty", appindicator.CATEGORY_APPLICATION_STATUS)
34 # self.ind.set_status (appindicator.STATUS_ACTIVE)
35 self.statusIcon = gtk.StatusIcon()
36 self.statusIcon.set_from_stock(gtk.STOCK_CDROM)
37 self.statusIcon.set_visible(True)
38 self.statusIcon.set_tooltip("Mounty")
39 self.statusIcon.connect("popup-menu", self.on_right_click)
40 # End XFCEpatch
42 self.isos = {}
44 client = gconf.client_get_default()
45 if client.get_bool('/apps/mounty/remember-mounts'):
46 mounts = client.get_list('/apps/mounty/mounts', gconf.VALUE_STRING)
47 for iso_name in mounts:
48 try:
49 DiskImage(iso_name).mount()
50 except:
51 pass
52 if len(sys.argv) > 1:
53 for i in sys.argv[1:]:
54 DiskImage(sys.argv[i]).mount()
55 self.update_menu()
58 def quit(self, widget, data = None):
59 client = gconf.client_get_default()
61 if client.get_bool('/apps/mounty/remember-mounts'):
62 iso_list = []
63 for iso in self.isos:
64 iso_list.append(iso)
65 else:
66 iso_list = []
68 client.set_list('/apps/mounty/mounts', gconf.VALUE_STRING, iso_list)
69 gtk.main_quit()
71 def update_menu(self):
72 self.isos = {}
74 def umount(widget, iso_name, data = None):
75 self.isos[iso_name].umount()
76 self.update_menu()
77 notification = pynotify.Notification(_('Disk Image Unmounted'), os.path.basename(iso_name), 'media-eject')
78 notification.show()
80 def browse(widget, iso_name, data = None):
81 self.isos[iso_name].browse()
83 def burn(widget, iso_name, data = None):
84 self.isos[iso_name].burn()
86 try:
87 mtab_path = os.path.join(os.path.expanduser('~'),'.mtab.fuseiso')
88 mtab = open(mtab_path).read().split('\n')
89 except:
90 mtab = []
92 menu = gtk.Menu()
93 menu.show()
94 show_separator = False
95 for line in mtab:
96 if line:
97 show_separator = True
98 items = line.split(' ')
99 items[0] = items[0].replace('\\040',' ')
100 iso = DiskImage(items[0])
101 self.isos[items[0]] = iso
103 item = gtk.MenuItem(os.path.basename(items[0]))
104 #item.set_image(gtk.image_new_from_icon_name('media-cdrom',gtk.ICON_SIZE_MENU))
105 item.show()
106 item.connect("activate", browse, items[0])
107 menu.append(item)
109 # item = gtk.MenuItem(_(' Burn'))
110 # item.show()
111 # item.connect("activate", burn, items[0])
112 # menu.append(item)
114 item = gtk.MenuItem(_(' Eject'))
115 item.show()
116 item.connect("activate", umount, items[0])
117 menu.append(item)
119 separator = gtk.MenuItem()
120 separator.show()
121 menu.append(separator)
123 image = gtk.MenuItem(_('Open Disk Image...'))
124 image.connect("activate", self.add_image)
125 image.show()
126 menu.append(image)
128 # item = gtk.CheckMenuItem(_('Remember mounted images'))
129 # client = gconf.client_get_default()
130 # item.set_active(client.get_bool('/apps/mounty/remember-mounts'))
131 # item.connect("activate", self.set_remember)
132 # item.show()
133 # menu.append(item)
135 # item = gtk.CheckMenuItem(_('Load at startup'))
136 # if os.path.exists(os.path.join(os.path.expanduser('~'), '.config', 'autostart', 'mounty-autostart.desktop')):
137 # item.set_active(True)
138 # item.connect("activate", self.set_startup)
139 # item.show()
140 # menu.append(item)
142 item = gtk.MenuItem(_('About'))
143 item.connect("activate", self.show_about)
144 item.show()
145 menu.append(item)
147 # Begin XFCEpatch
148 # item = gtk.MenuItem(_('Quit'))
149 # item.connect("activate", self.quit)
150 # item.show()
151 # menu.append(item)
152 # self.ind.set_menu(menu)
153 try:
154 self.statusIcon.disconnect(self.handlerid)
155 except:
156 pass
157 self.handlerid = self.statusIcon.connect("activate", self.on_left_click, menu)
159 def on_left_click(self, widget, data):
160 data.show_all()
161 data.popup(None, None, gtk.status_icon_position_menu, 1, gtk.get_current_event_time(), self.statusIcon)
163 def on_right_click(self, button, time, data):
164 quit_menu = gtk.Menu()
165 quit_menu_item = gtk.MenuItem("Quit")
166 quit_menu_item.connect("activate", self.on_quit, self.statusIcon)
167 quit_menu.append(quit_menu_item)
168 quit_menu.show_all()
169 quit_menu.popup(None, None, gtk.status_icon_position_menu, 1, gtk.get_current_event_time(), self.statusIcon)
171 def on_quit(self, widget, event):
172 gtk.main_quit()
173 # End XFCEpatch
175 def show_about(self, widget, data = None):
176 about = gtk.AboutDialog()
177 about.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
178 about.set_program_name("Mounty")
179 about.set_version(APP_VERSION)
180 about.set_authors([_("Krasimir S. Stefanov <lokiisyourmaster@gmail.com>")])
181 about.set_website("http://skss.learnfree.eu/")
182 about.set_translator_credits(_("Bulgarian - Krasimir S. Stefanov <lokiisyourmaster@gmail.com>"))
183 about.set_logo_icon_name('media-cdrom')
184 license = _('''Mounty - Mount disk images from app indicator
185 Copyright (C) 2011 Krasimir S. Stefanov
187 This program is free software: you can redistribute it and/or modify
188 it under the terms of the GNU General Public License as published by
189 the Free Software Foundation, either version 3 of the License, or
190 (at your option) any later version.
192 This program is distributed in the hope that it will be useful,
193 but WITHOUT ANY WARRANTY; without even the implied warranty of
194 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195 GNU General Public License for more details.
197 You should have received a copy of the GNU General Public License
198 along with this program. If not, see <http://www.gnu.org/licenses/>.''')
199 about.set_license(license)
200 about.run()
201 about.hide()
203 def set_startup(self, widget, data = None):
204 autostart = os.path.join(os.path.expanduser('~'), '.config', 'autostart', 'mounty-autostart.desktop')
205 if widget.get_active():
206 shutil.copy2('/usr/share/applications/mounty.desktop', autostart)
207 else:
208 os.remove(autostart)
211 def set_remember(self, widget, data = None):
212 client = gconf.client_get_default()
213 client.set_bool('/apps/mounty/remember-mounts', int(widget.get_active()))
215 def add_image(self, widget, data = None):
216 dialog = gtk.FileChooserDialog(_('Open Disk Image...'),
217 None,
218 gtk.FILE_CHOOSER_ACTION_OPEN,
219 (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
220 gtk.STOCK_OPEN, gtk.RESPONSE_OK))
221 dialog.set_default_response(gtk.RESPONSE_OK)
223 filter = gtk.FileFilter()
224 filter.set_name(_("Disk Images"))
225 filter.add_pattern("*.iso")
226 filter.add_pattern("*.img")
227 filter.add_pattern("*.bin")
228 filter.add_pattern("*.mdf")
229 filter.add_pattern("*.nrg")
230 dialog.add_filter(filter)
232 filter = gtk.FileFilter()
233 filter.set_name(_("All files"))
234 filter.add_pattern("*")
235 dialog.add_filter(filter)
238 response = dialog.run()
239 if response == gtk.RESPONSE_OK:
240 iso_name = dialog.get_filename()
241 iso = DiskImage(iso_name)
242 if iso.mount():
243 notification = pynotify.Notification(_('Disk Image Mounted'), os.path.basename(iso_name), 'media-cdrom')
244 notification.show()
245 else:
246 notification = pynotify.Notification(_('Error while mounting disk image'), os.path.basename(iso_name), 'error')
247 notification.show()
249 dialog.destroy()
250 while gtk.events_pending():
251 gtk.main_iteration(False)
252 self.update_menu()
254 if __name__ == "__main__":
255 application()
256 gtk.main()