Ejemplo n.º 1
0
    def populate(self):
        db_conn = create_db_connection()
        mangas_rows = db_conn.execute('SELECT * FROM mangas ORDER BY last_read DESC').fetchall()

        if len(mangas_rows) == 0:
            if self.window.overlay.is_ancestor(self.window):
                self.window.remove(self.window.overlay)

            # Display first start message
            self.window.add(self.window.first_start_grid)

            return

        if self.window.first_start_grid.is_ancestor(self.window):
            self.window.remove(self.window.first_start_grid)

        if not self.window.overlay.is_ancestor(self.window):
            self.window.add(self.window.overlay)

        # Clear library flowbox
        for child in self.flowbox.get_children():
            child.destroy()

        # Populate flowbox with mangas
        for row in mangas_rows:
            self.add_manga(Manga.get(row['id']))

        db_conn.close()
Ejemplo n.º 2
0
        def confirm_callback():
            # Stop Downloader & Updater
            self.window.downloader.stop()
            self.window.updater.stop()

            while self.window.downloader.running or self.window.updater.running:
                time.sleep(0.1)
                continue

            # Safely delete manga in DB
            self.manga.delete()

            # Restart Downloader & Updater
            self.window.downloader.start()
            self.window.updater.start()

            # Finally, update and show library
            db_conn = create_db_connection()
            nb_mangas = db_conn.execute('SELECT count(*) FROM mangas').fetchone()[0]
            db_conn.close()

            if nb_mangas == 0:
                # Library is now empty
                self.window.library.populate()
            else:
                self.window.library.on_manga_deleted(self.manga)

            self.window.library.show()
Ejemplo n.º 3
0
    def show_page(self, name):
        if name == 'search':
            if self.page == 'servers':
                self.custom_title_search_page_searchentry.set_placeholder_text(_('Search in {0}…').format(self.server.name))
                self.clear_search()
                self.search()
            else:
                self.custom_title_search_page_searchentry.grab_focus_without_selecting()
        elif name == 'manga':
            self.custom_title_manga_page_label.set_text(self.manga_data['name'])

            # Check if selected manga is already in library
            db_conn = create_db_connection()
            row = db_conn.execute(
                'SELECT * FROM mangas WHERE slug = ? AND server_id = ?',
                (self.manga_data['slug'], self.manga_data['server_id'])
            ).fetchone()
            db_conn.close()

            if row:
                self.manga = Manga.get(row['id'], self.server)

                self.read_button.show()
                self.add_button.hide()
            else:
                self.add_button.show()
                self.read_button.hide()

        self.custom_title_stack.set_visible_child_name(name)
        self.stack.set_visible_child_name(name)
        self.page = name
Ejemplo n.º 4
0
    def toggle_selected_chapters_read_status(self, action, param, read):
        chapters_ids = []
        chapters_data = []

        self.card.window.activity_indicator.start()

        # First, update DB
        for row in self.listbox.get_selected_rows():
            chapter = row.chapter

            if chapter.pages:
                pages = deepcopy(chapter.pages)
                for page in pages:
                    page['read'] = read
            else:
                pages = None
            last_page_read_index = None if chapter.read == read == 0 else chapter.last_page_read_index

            chapters_ids.append(chapter.id)
            chapters_data.append(dict(
                pages=pages,
                read=read,
                recent=False,
                last_page_read_index=last_page_read_index,
            ))

        db_conn = create_db_connection()

        with db_conn:
            res = update_rows(db_conn, 'chapters', chapters_ids, chapters_data)

        db_conn.close()

        # Then, if DB update succeeded, refresh chapters rows
        def run():
            # Use countdown to stop activity indicator and leave selection mode
            self.populate_countdown = len(self.listbox.get_selected_rows())

            for row in self.listbox.get_selected_rows():
                chapter = row.chapter

                if chapter.pages:
                    for chapter_page in chapter.pages:
                        chapter_page['read'] = read
                if chapter.read == read == 0:
                    chapter.last_page_read_index = None
                chapter.read = read
                chapter.recent = False

                GLib.idle_add(self.populate_chapter_row, row)
                time.sleep(0.0025)

        if res:
            thread = threading.Thread(target=run)
            thread.daemon = True
            thread.start()
        else:
            self.card.window.activity_indicator.stop()
            self.card.leave_selection_mode()
Ejemplo n.º 5
0
    def update_library(self):
        self.update_library_flag = True

        db_conn = create_db_connection()
        rows = db_conn.execute('SELECT * FROM mangas ORDER BY last_read DESC').fetchall()
        db_conn.close()

        for row in rows:
            self.add(Manga.get(row['id']))

        self.start()
Ejemplo n.º 6
0
    def on_manga_added(self, manga):
        """Called from 'Add dialog' when user clicks on [+] button"""
        db_conn = create_db_connection()
        nb_mangas = db_conn.execute('SELECT count(*) FROM mangas').fetchone()[0]
        db_conn.close()

        if nb_mangas == 1:
            # Library was previously empty
            self.populate()
        else:
            self.add_manga(manga, position=0)
Ejemplo n.º 7
0
    def populate(self):
        db_conn = create_db_connection()
        records = db_conn.execute(
            'SELECT * FROM downloads ORDER BY date ASC').fetchall()
        db_conn.close()

        if records:
            for record in records:
                download = Download.get(record['id'])

                row = DownloadRow(download)
                self.listbox.add(row)

            self.listbox.show_all()
            self.stack.set_visible_child_name('list')
        else:
            self.stack.set_visible_child_name('empty')
Ejemplo n.º 8
0
        def run(exclude_errors=False):
            db_conn = create_db_connection()
            if exclude_errors:
                rows = db_conn.execute(
                    'SELECT * FROM downloads WHERE status != "error" ORDER BY date ASC'
                ).fetchall()
            else:
                rows = db_conn.execute(
                    'SELECT * FROM downloads ORDER BY date ASC').fetchall()
            db_conn.close()

            interrupted = False
            for row in rows:
                if self.stop_flag:
                    break

                download = Download.get(row['id'])
                if download is None:
                    # Download has been removed in the meantime
                    continue

                chapter = download.chapter

                download.update(dict(status='downloading'))
                GLib.idle_add(notify_download_started, download)

                try:
                    if chapter.update_full() and len(chapter.pages) > 0:
                        error_counter = 0
                        success_counter = 0
                        for index, _page in enumerate(chapter.pages):
                            if self.stop_flag:
                                interrupted = True
                                break

                            if chapter.get_page_path(index) is None:
                                path = chapter.get_page(index)
                                if path is not None:
                                    success_counter += 1
                                    download.update(
                                        dict(percent=(index + 1) * 100 /
                                             len(chapter.pages)))
                                else:
                                    error_counter += 1
                                    download.update(dict(errors=error_counter))

                                GLib.idle_add(notify_download_progress,
                                              download, success_counter,
                                              error_counter)

                                if index < len(chapter.pages
                                               ) - 1 and not self.stop_flag:
                                    time.sleep(DOWNLOAD_DELAY)
                            else:
                                success_counter += 1

                        if interrupted:
                            download.update(dict(status='pending'))
                        else:
                            if error_counter == 0:
                                # All pages were successfully downloaded
                                chapter.update(dict(downloaded=1))
                                download.delete()
                                GLib.idle_add(notify_download_success, chapter)
                            else:
                                # At least one page failed to be downloaded
                                download.update(dict(status='error'))
                                GLib.idle_add(notify_download_error, download)
                    else:
                        # Possible causes:
                        # - Empty chapter
                        # - Outdated chapter info
                        # - Server has undergone changes (API, HTML) and plugin code is outdated
                        download.update(dict(status='error'))
                        GLib.idle_add(notify_download_error, download)
                except Exception as e:
                    # Possible causes:
                    # - No Internet connection
                    # - Connexion timeout, read timeout
                    # - Server down
                    download.update(dict(status='error'))
                    user_error_message = log_error_traceback(e)
                    GLib.idle_add(notify_download_error, download,
                                  user_error_message)

            if not rows or self.stop_flag:
                self.running = False
                GLib.idle_add(self.emit, 'ended')
            else:
                # Continue, new downloads may have been added in the meantime
                run(exclude_errors=True)