예제 #1
0
    def _on_connect(self):
        """Handle connecting for the first time."""
        print("Client connected.")
        self._user_list, self._conv_list = (
            yield from hangups.build_user_conversation_list(self._client))
        self._conv_list.on_event.add_observer(self._on_event)
        if not self._disable_notifier:
            self._notifier = Notifier(self._conv_list)

        donald = Trumpisms()

        # Start Swift server
        handlers = (self._client, self._conv_list)
        swift = Swift(*handlers)
        self.bank = Bank(*handlers, swift=swift, donald=donald)
예제 #2
0
 def _on_connect(self):
     """Handle connecting for the first time."""
     self._user_list, self._conv_list = (
         yield from hangups.build_user_conversation_list(self._client))
     self._conv_list.on_event.add_observer(self._on_event)
     if not self._disable_notifier:
         self._notifier = Notifier(self._conv_list)
     # show the conversation menu
     conv_picker = ConversationPickerWidget(self._conv_list,
                                            self.on_select_conversation,
                                            self._keys)
     self._tabbed_window = TabbedWindowWidget(self._keys)
     self._tabbed_window.set_tab(conv_picker,
                                 switch=True,
                                 title='Conversations')
     self._urwid_loop.widget = self._tabbed_window
예제 #3
0
파일: __main__.py 프로젝트: m0nt3-q/hangups
 def _on_connect(self, initial_data):
     """Handle connecting for the first time."""
     self._user_list = yield from hangups.build_user_list(
         self._client, initial_data)
     self._conv_list = hangups.ConversationList(
         self._client, initial_data.conversation_states, self._user_list,
         initial_data.sync_timestamp)
     self._conv_list.on_event.add_observer(self._on_event)
     self._notifier = Notifier(self._conv_list)
     # show the conversation menu
     conv_picker = ConversationPickerWidget(self._conv_list,
                                            self.on_select_conversation)
     self._tabbed_window = TabbedWindowWidget(self._keys)
     self._tabbed_window.set_tab(conv_picker,
                                 switch=True,
                                 title='Conversations')
     self._urwid_loop.widget = self._tabbed_window
예제 #4
0
def on_connect():
    """Handle connecting for the first time."""
    global client, disable_notifier, conv_list, user_list

    print("Building conversation and user list")
    user_list, conv_list = (
        yield from hangups.build_user_conversation_list(client)
    )

    print("Adding contacts")
    for user in sorted(user_list.get_all(), key=lambda u: u.full_name):
        user_data = {
            "id_": user.id_.chat_id,
            "name": user.full_name,
            "first_name": user.first_name,
            "photo_url": "https:" + user.photo_url if user.photo_url else None,
            "emails": user.emails,
        }
        if not user.is_self:
            pyotherside.send('add-contact', user_data)

    print("Added conversations observer")
    conv_list.on_event.add_observer(on_event)
    if not disable_notifier:
        notifier = Notifier(conv_list)

    convs = sorted(conv_list.get_all(), reverse=True,
                   key=lambda c: c.last_modified)

    print("Showing conversations")
    for conv in convs:
        conv_data = model.get_conv_data(conv)
        pyotherside.send('add-conversation', conv_data)
        ctrl = ConversationController(conv)
        ctrl.update_online_status()
        conv_controllers[conv.id_] = ctrl

    print("Setting presence")
    set_client_presence(True)

    pyotherside.send('show-conversations-page')
예제 #5
0
    def on_connect(self, initial_data):
        """Handle connecting for the first time (callback)"""
        print('Connected')
        self.user_list = hangups.UserList(
            self.client, initial_data.self_entity, initial_data.entities,
            initial_data.conversation_participants)
        self.conv_list = hangups.ConversationList(
            self.client, initial_data.conversation_states, self.user_list,
            initial_data.sync_timestamp)
        self.conv_list.on_event.add_observer(self.on_event)

        # Setup notifications
        self.notifier = Notifier(self.conv_list)

        # Setup conversations window
        self.messages_dialog.init_conversations(self.client, self.conv_list)

        # Setup conversations list window and show it
        self.conversations_dialog.init_conversations(self.client,
                                                     self.conv_list)
        self.conversations_dialog.show()
예제 #6
0
def on_connect(initial_data):
    """Handle connecting for the first time."""
    global client, disable_notifier, conv_list, user_list
    print("Building user list")
    user_list = yield from hangups.build_user_list(client, initial_data)

    print("Adding contacts")
    for user in sorted(user_list.get_all(), key=lambda u: u.full_name):
        user_data = {
            "id_": user.id_.chat_id,
            "name": user.full_name,
            "first_name": user.first_name,
            "photo_url": "https:" + user.photo_url if user.photo_url else None,
            "emails": user.emails,
        }
        if not user.is_self:
            pyotherside.send('add-contact', user_data)

    print("Creating conversations list")
    conv_list = hangups.ConversationList(client,
                                         initial_data.conversation_states,
                                         user_list,
                                         initial_data.sync_timestamp)
    print("Added conversations oveserver")
    conv_list.on_event.add_observer(on_event)
    if not disable_notifier:
        notifier = Notifier(conv_list)

    convs = sorted(conv_list.get_all(),
                   reverse=True,
                   key=lambda c: c.last_modified)

    print("Showing conversations")
    for conv in convs:
        conv_data = {
            "title":
            get_conv_name(conv),
            "status_message":
            "",
            "icon":
            get_conv_icon(conv),
            "id_":
            conv.id_,
            "first_message_loaded":
            False,
            "unread_count":
            get_unread_messages_count(conv),
            "is_quiet":
            conv.is_quiet,
            "users": [{
                "id_":
                user.id_[0],
                "full_name":
                user.full_name,
                "first_name":
                user.first_name,
                "photo_url":
                "https:" + user.photo_url if user.photo_url else None,
                "emails":
                user.emails,
                "is_self":
                user.is_self
            } for user in conv.users]
        }
        pyotherside.send('add-conversation', conv_data)
        ctrl = ConversationController(conv)
        conv_controllers[conv.id_] = ctrl

    pyotherside.send('show-conversations-page')
예제 #7
0
def main():
    """Main entry point."""
    # Build default paths for files.
    dirs = appdirs.AppDirs('hangups', 'hangups')
    default_log_path = os.path.join(dirs.user_log_dir, 'hangups.log')
    default_token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt')
    default_config_path = 'hangups.conf'
    user_config_path = os.path.join(dirs.user_config_dir, 'hangups.conf')

    # Create a default empty config file if does not exist.
    dir_maker(user_config_path)
    if not os.path.isfile(user_config_path):
        with open(user_config_path, 'a') as cfg:
            cfg.write("")

    parser = configargparse.ArgumentParser(
        prog='hangups', default_config_files=[default_config_path,
                                              user_config_path],
        formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
        add_help=False,  # Disable help so we can add it to the correct group.
    )
    general_group = parser.add_argument_group('General')
    general_group.add('-h', '--help', action='help',
                      help='show this help message and exit')
    general_group.add('--token-path', default=default_token_path,
                      help='path used to store OAuth refresh token')
    general_group.add('--date-format', default='< %y-%m-%d >',
                      help='date format string')
    general_group.add('--time-format', default='(%I:%M:%S %p)',
                      help='time format string')
    general_group.add('-c', '--config', help='configuration file path',
                      is_config_file=True, default=user_config_path)
    general_group.add('-v', '--version', action='version',
                      version='hangups {}'.format(hangups.__version__))
    general_group.add('-d', '--debug', action='store_true',
                      help='log detailed debugging messages')
    general_group.add('--log', default=default_log_path, help='log file path')
    key_group = parser.add_argument_group('Keybindings')
    key_group.add('--key-next-tab', default='ctrl d',
                  help='keybinding for next tab')
    key_group.add('--key-prev-tab', default='ctrl u',
                  help='keybinding for previous tab')
    key_group.add('--key-close-tab', default='ctrl w',
                  help='keybinding for close tab')
    key_group.add('--key-quit', default='ctrl e',
                  help='keybinding for quitting')
    key_group.add('--key-menu', default='ctrl n',
                  help='keybinding for context menu')
    key_group.add('--key-up', default='k',
                  help='keybinding for alternate up key')
    key_group.add('--key-down', default='j',
                  help='keybinding for alternate down key')
    notification_group = parser.add_argument_group('Notifications')
    notification_group.add('-n', '--disable-notifications',
                           action='store_true',
                           help='disable desktop notifications')
    notification_group.add('-D', '--discreet-notifications',
                           action='store_true',
                           help='hide message details in notifications')

    # add color scheme options
    col_group = parser.add_argument_group('Colors')
    col_group.add('--col-scheme', choices=COL_SCHEMES.keys(),
                  default='default', help='colour scheme to use')
    col_group.add('--col-palette-colors', choices=('16', '88', '256'),
                  default=16, help='Amount of available colors')
    for name in COL_SCHEME_NAMES:
        col_group.add('--col-' + name.replace('_', '-') + '-fg',
                      help=name + ' foreground color')
        col_group.add('--col-' + name.replace('_', '-') + '-bg',
                      help=name + ' background color')

    args = parser.parse_args()

    # Create all necessary directories.
    for path in [args.log, args.token_path]:
        dir_maker(path)

    logging.basicConfig(filename=args.log,
                        level=logging.DEBUG if args.debug else logging.WARNING,
                        format=LOG_FORMAT)
    # urwid makes asyncio's debugging logs VERY noisy, so adjust the log level:
    logging.getLogger('asyncio').setLevel(logging.WARNING)

    datetimefmt = {'date': args.date_format,
                   'time': args.time_format}

    # setup color scheme
    palette_colors = int(args.col_palette_colors)

    col_scheme = COL_SCHEMES[args.col_scheme]
    for name in COL_SCHEME_NAMES:
        col_scheme = add_color_to_scheme(col_scheme, name,
                                         getattr(args, 'col_' + name + '_fg'),
                                         getattr(args, 'col_' + name + '_bg'),
                                         palette_colors)

    if not args.disable_notifications:
        notifier = Notifier(args.discreet_notifications)
    else:
        notifier = None

    try:
        ChatUI(
            args.token_path, {
                'next_tab': args.key_next_tab,
                'prev_tab': args.key_prev_tab,
                'close_tab': args.key_close_tab,
                'quit': args.key_quit,
                'menu': args.key_menu,
                'up': args.key_up,
                'down': args.key_down
            }, col_scheme, palette_colors, datetimefmt, notifier
        )
    except KeyboardInterrupt:
        sys.exit('Caught KeyboardInterrupt, exiting abnormally')
    except:
        # urwid will prevent some exceptions from being printed unless we use
        # print a newline first.
        print('')
        raise