9 from diskimage
import DiskImage
18 DIR
= '/usr/share/locale/'
20 locale
.setlocale(locale
.LC_ALL
, '')
21 gettext
.bindtextdomain(APP
, DIR
)
22 gettext
.textdomain(APP
)
25 # register to libnotify
26 if not pynotify
.init("mounty"):
27 error(_("Cannot initialize libnotify"))
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
)
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
:
49 DiskImage(iso_name
).mount()
53 for i
in sys
.argv
[1:]:
54 DiskImage(sys
.argv
[i
]).mount()
58 def quit(self
, widget
, data
= None):
59 client
= gconf
.client_get_default()
61 if client
.get_bool('/apps/mounty/remember-mounts'):
68 client
.set_list('/apps/mounty/mounts', gconf
.VALUE_STRING
, iso_list
)
71 def update_menu(self
):
74 def umount(widget
, iso_name
, data
= None):
75 self
.isos
[iso_name
].umount()
77 notification
= pynotify
.Notification(_('Disk Image Unmounted'), os
.path
.basename(iso_name
), 'media-eject')
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()
87 mtab_path
= os
.path
.join(os
.path
.expanduser('~'),'.mtab.fuseiso')
88 mtab
= open(mtab_path
).read().split('\n')
94 show_separator
= False
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))
106 item
.connect("activate", browse
, items
[0])
109 # item = gtk.MenuItem(_(' Burn'))
111 # item.connect("activate", burn, items[0])
114 item
= gtk
.MenuItem(_(' Eject'))
116 item
.connect("activate", umount
, items
[0])
119 separator
= gtk
.MenuItem()
121 menu
.append(separator
)
123 image
= gtk
.MenuItem(_('Open Disk Image...'))
124 image
.connect("activate", self
.add_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)
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)
142 item
= gtk
.MenuItem(_('About'))
143 item
.connect("activate", self
.show_about
)
148 # item = gtk.MenuItem(_('Quit'))
149 # item.connect("activate", self.quit)
152 # self.ind.set_menu(menu)
154 self
.statusIcon
.disconnect(self
.handlerid
)
157 self
.handlerid
= self
.statusIcon
.connect("activate", self
.on_left_click
, menu
)
159 def on_left_click(self
, widget
, data
):
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
)
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
):
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
)
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
)
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...'),
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
)
243 notification
= pynotify
.Notification(_('Disk Image Mounted'), os
.path
.basename(iso_name
), 'media-cdrom')
246 notification
= pynotify
.Notification(_('Error while mounting disk image'), os
.path
.basename(iso_name
), 'error')
250 while gtk
.events_pending():
251 gtk
.main_iteration(False)
254 if __name__
== "__main__":