HubicGTK: Check-in [c489be0973]

HubicGTK is a system tray icon for hubiC, the online storage service by OVH SAS.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[UPD] code refactoring (uniformize quote marks)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gtk3
Files: files | file ages | folders
SHA1:c489be0973b9a29660572daf424455cce000ef63
User & Date: milouse 2016-08-27 01:04:14
Context
2016-09-06
16:38
[UPD] impersonate hubic autostart desktop file to prevent main hubic process to always autostart check-in: b250e3bd70 user: milouse tags: v1.0-alpha5, gtk3
2016-08-27
01:04
[UPD] code refactoring (uniformize quote marks) check-in: c489be0973 user: milouse tags: gtk3
2016-08-15
08:36
[UPD] alpha stage PKGBUILD check-in: f0206f6d27 user: milouse tags: gtk3
Changes

Changes to hubic-gtk.py.

47
48
49
50
51
52
53


54
55
56
57
58
59
60
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
...
653
654
655
656
657
658
659

660
661
662
663
664
665
666
...
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    'Unsynchronized': _('Unsynchronized'),
    'NoStatus': _('NoStatus'),
    'Error': _('Error'),
    'Starting': _('Starting'),
    'Killed': _('Killed')
}



def get_bool_conf_option(config, section, option):
    if config.has_option(section, option):
        v = config.get(section, option)
        return str(v).lower() in ('yes', 'true', 't', '1')
    return False


................................................................................
    def on_networking_change(self, state):
        if self.hubic_state != 'Killed' and self.hubic_state != 'Starting':
            if state == 70:
                # Connectivity is up and not only local
                self.last_messages.append((
                    '',
                    _('{0} Resume Hubic as network is up').format(
                        time.strftime("[%d/%m/%Y %H:%M]")
                    )
                ))
                self.hubic_account_iface.SetPauseState(False)
            elif self.hubic_state != 'Paused':
                self.last_messages.append((
                    '',
                    _('{0} Pause Hubic as network connectivity seems to be down').format(
                        time.strftime("[%d/%m/%Y %H:%M]")
                    )
                ))
                self.hubic_account_iface.SetPauseState(True)


    def on_state_change(self, old_state, new_state):
        if new_state == 'NotConnected' and old_state == 'Connecting':
................................................................................
        self.tray.set_from_icon_name(tray_icon)
        self.tray.set_tooltip_text(tray_tooltip)


    def on_file_change(self, file_path):
        [status, isPublished, canBePublished] = self.hubic_account_iface.GetItemStatus(file_path)
        message = self.ff_helper.crunch_path(file_path) + ': ' + HUBIC_POSSIBLE_STATUS[status]
        self.last_messages.append((file_path, time.strftime("[%d/%m/%Y %H:%M]") + ' ' + message))

        if self.show_messages:
            nota = Notify.Notification.new('HubicGTK', message)
            nota.show()


    def on_message(self, urgency, message, file_path):
        if file_path != '':
            [status, isPublished, canBePublished] = self.hubic_account_iface.GetItemStatus(file_path)
            info_message = message + "\n" + self.ff_helper.crunch_path(file_path) + ': ' + HUBIC_POSSIBLE_STATUS[status]
        else:
            info_message = message

        self.last_messages.append((file_path, time.strftime("[%d/%m/%Y %H:%M]") + ' ' + info_message))

        if self.show_messages or urgency == 2 or urgency == 3:
            nota = Notify.Notification.new('HubicGTK', message)

            if urgency == 1 or urgency == 2:
                nota.set_urgency(Notify.Urgency.NORMAL)
            elif urgency == 3:
................................................................................
        self.config.set('general', 'notify', self.show_messages)

        with open(os.path.join(xdg_config_home, 'hubiC', 'status_icon.conf'), 'wb') as configfile:
            self.config.write(configfile)
            configfile.close()



    def toggle_must_autostart(self, widget):
        self.must_autostart = widget.get_active()
        if not os.path.isdir(os.path.join(xdg_config_home, 'autostart')):
            self.must_autostart = False
            return False
        file_yet_exists = os.path.isfile(os.path.join(xdg_config_home, 'autostart', 'hubic-gtk.desktop'))
        if not file_yet_exists and self.must_autostart:
................................................................................

    def  show_about_dialog(self, widget):
        about_dialog = Gtk.AboutDialog()
        about_dialog.set_destroy_with_parent(True)
        about_dialog.set_icon_name('HubicGTK')
        about_dialog.set_name('HubicGTK')
        about_dialog.set_website('https://projects.depar.is/hubic-gtk')
        about_dialog.set_comments(_("A status icon for hubiC on Gnu/Linux, providing an easy way to manage your encfs synchronised folders too."))
        about_dialog.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_scale('/usr/share/icons/hicolor/scalable/apps/hubic-gtk.svg',
                                                                      128, 128, True))
        about_dialog.set_version(HUBIC_STATUS_VERSION)

        hubic_b_version = subprocess.check_output('hubic help | head -n2', shell=True)
        mono_b_version = subprocess.check_output('mono -V | head -n2', shell=True)
        hubic_version = "\n\n{0}{1}".format(hubic_b_version.decode(), mono_b_version.decode())
        about_dialog.set_copyright(_("HubicGTK is released under the WTF public license\nStatus icons use famfamfam silk icons, released under CC By 2.5 license") + hubic_version)
        about_dialog.set_authors(['√Čtienne Deparis <etienne@depar.is>'])
        about_dialog.run()
        about_dialog.destroy()


    def kthxbye(self, widget):
        self.cleanup_dbus_infos(None)
        Gtk.main_quit()


if __name__ == "__main__":
    # Install signal handlers
    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGTERM,
                         Gtk.main_quit, None)
    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
                         Gtk.main_quit, None)
    SystrayIconApp()
    Gtk.main()







>
>







 







|







|







 







|













|







 







>







 







|







|










|







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
...
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
...
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
...
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    'Unsynchronized': _('Unsynchronized'),
    'NoStatus': _('NoStatus'),
    'Error': _('Error'),
    'Starting': _('Starting'),
    'Killed': _('Killed')
}

# TODO replace with now standard getboolean
# https://docs.python.org/3.5/library/configparser.html#supported-datatypes
def get_bool_conf_option(config, section, option):
    if config.has_option(section, option):
        v = config.get(section, option)
        return str(v).lower() in ('yes', 'true', 't', '1')
    return False


................................................................................
    def on_networking_change(self, state):
        if self.hubic_state != 'Killed' and self.hubic_state != 'Starting':
            if state == 70:
                # Connectivity is up and not only local
                self.last_messages.append((
                    '',
                    _('{0} Resume Hubic as network is up').format(
                        time.strftime('[%d/%m/%Y %H:%M]')
                    )
                ))
                self.hubic_account_iface.SetPauseState(False)
            elif self.hubic_state != 'Paused':
                self.last_messages.append((
                    '',
                    _('{0} Pause Hubic as network connectivity seems to be down').format(
                        time.strftime('[%d/%m/%Y %H:%M]')
                    )
                ))
                self.hubic_account_iface.SetPauseState(True)


    def on_state_change(self, old_state, new_state):
        if new_state == 'NotConnected' and old_state == 'Connecting':
................................................................................
        self.tray.set_from_icon_name(tray_icon)
        self.tray.set_tooltip_text(tray_tooltip)


    def on_file_change(self, file_path):
        [status, isPublished, canBePublished] = self.hubic_account_iface.GetItemStatus(file_path)
        message = self.ff_helper.crunch_path(file_path) + ': ' + HUBIC_POSSIBLE_STATUS[status]
        self.last_messages.append((file_path, time.strftime('[%d/%m/%Y %H:%M]') + ' ' + message))

        if self.show_messages:
            nota = Notify.Notification.new('HubicGTK', message)
            nota.show()


    def on_message(self, urgency, message, file_path):
        if file_path != '':
            [status, isPublished, canBePublished] = self.hubic_account_iface.GetItemStatus(file_path)
            info_message = message + "\n" + self.ff_helper.crunch_path(file_path) + ': ' + HUBIC_POSSIBLE_STATUS[status]
        else:
            info_message = message

        self.last_messages.append((file_path, time.strftime('[%d/%m/%Y %H:%M]') + ' ' + info_message))

        if self.show_messages or urgency == 2 or urgency == 3:
            nota = Notify.Notification.new('HubicGTK', message)

            if urgency == 1 or urgency == 2:
                nota.set_urgency(Notify.Urgency.NORMAL)
            elif urgency == 3:
................................................................................
        self.config.set('general', 'notify', self.show_messages)

        with open(os.path.join(xdg_config_home, 'hubiC', 'status_icon.conf'), 'wb') as configfile:
            self.config.write(configfile)
            configfile.close()


    # TODO check the validity of this desktop file
    def toggle_must_autostart(self, widget):
        self.must_autostart = widget.get_active()
        if not os.path.isdir(os.path.join(xdg_config_home, 'autostart')):
            self.must_autostart = False
            return False
        file_yet_exists = os.path.isfile(os.path.join(xdg_config_home, 'autostart', 'hubic-gtk.desktop'))
        if not file_yet_exists and self.must_autostart:
................................................................................

    def  show_about_dialog(self, widget):
        about_dialog = Gtk.AboutDialog()
        about_dialog.set_destroy_with_parent(True)
        about_dialog.set_icon_name('HubicGTK')
        about_dialog.set_name('HubicGTK')
        about_dialog.set_website('https://projects.depar.is/hubic-gtk')
        about_dialog.set_comments(_('A status icon for hubiC on Gnu/Linux, providing an easy way to manage your encfs synchronised folders too.'))
        about_dialog.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_scale('/usr/share/icons/hicolor/scalable/apps/hubic-gtk.svg',
                                                                      128, 128, True))
        about_dialog.set_version(HUBIC_STATUS_VERSION)

        hubic_b_version = subprocess.check_output('hubic help | head -n2', shell=True)
        mono_b_version = subprocess.check_output('mono -V | head -n2', shell=True)
        hubic_version = "\n\n{0}{1}".format(hubic_b_version.decode(), mono_b_version.decode())
        about_dialog.set_copyright(_('HubicGTK is released under the WTF public license\nStatus icons use famfamfam silk icons, released under CC By 2.5 license') + hubic_version)
        about_dialog.set_authors(['√Čtienne Deparis <etienne@depar.is>'])
        about_dialog.run()
        about_dialog.destroy()


    def kthxbye(self, widget):
        self.cleanup_dbus_infos(None)
        Gtk.main_quit()


if __name__ == '__main__':
    # Install signal handlers
    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGTERM,
                         Gtk.main_quit, None)
    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
                         Gtk.main_quit, None)
    SystrayIconApp()
    Gtk.main()