コード例 #1
0
        def addEntryFunc():
            dbobj = HistoryDbModel.select().where(
                HistoryDbModel.url == url.toString()).first()
            if dbobj:
                # update
                before = self.HistoryEntry()
                before.id = dbobj.id
                before.count = dbobj.count
                before.date = QDateTime.fromMSecsSinceEpoch(dbobj.date)
                before.url = url
                before.urlString = before.url.toEncoded().data().decode()
                before.title = dbobj.title

                after = self.HistoryEntry()
                after.id = dbobj.id
                after.count = dbobj.count + 1
                after.date = QDateTime.currentDateTime()
                after.url = url
                after.urlString = after.url.toEncoded().data().decode()
                after.title = title
                after.fillDbobj(dbobj)
                dbobj.save()

                self.historyEntryEdited.emit(before, after)
            else:
                # insert
                dbobj = HistoryDbModel.create(
                    **{
                        'count': 1,
                        'date': QDateTime.currentMSecsSinceEpoch(),
                        'url': url.toString(),
                        'title': title,
                    })
                entry = self.HistoryEntry.CreateFromDbobj(dbobj)
                self.historyEntryAdded.emit(entry)
コード例 #2
0
    def createDomainQuery(cls, text):
        '''
        @param: text QString
        '''
        if not text or text == 'www.':
            return HistoryDbModel.select().where(HistoryDbModel.id == 0)

        withoutWww = text.startswith('w') and not text.startswith('www.')
        qs = HistoryDbModel.select()
        if withoutWww:
            qs = qs.where(
                ~HistoryDbModel.url.startswith('http://www.')
                & ~HistoryDbModel.url.startswith('https://www.')
                & (HistoryDbModel.url.startswith('http://%s' % text)
                   | HistoryDbModel.url.startswith('https://%s' % text)))
        else:
            qs = qs.where(
                HistoryDbModel.url.startswith('http://%s' % text)
                | HistoryDbModel.url.startswith('https://%s' % text)
                | (HistoryDbModel.url.startswith(
                    'http://www.%s' % text
                    | HistoryDbModel.url.startswith('https://www.%s' % text))))

        qs = qs.order_by(HistoryDbModel.date.desc()).limit(1)
        return qs
コード例 #3
0
    def clearHistory(self):
        HistoryDbModel.delete().execute()
        HistoryDbModel.raw('VACUUM').execute()

        gVar.app.webProfile().clearAllVisitedLinks()

        self.resetHistory.emit()
コード例 #4
0
    def _init(self):
        from .History import History
        minTs = HistoryDbModel.select(peewee.fn.Min(
            HistoryDbModel.date)).scalar()
        if minTs <= 0:
            return

        today = QDate.currentDate()
        week = today.addDays(1 - today.dayOfWeek())
        month = QDate(today.year(), today.month(), 1)
        currentTs = QDateTime.currentMSecsSinceEpoch()

        ts = currentTs
        while ts > minTs:
            tsDate = QDateTime.fromMSecsSinceEpoch(ts).date()
            endTs = 0
            itemName = ''

            if tsDate == today:
                endTs = QDateTime(today).toMSecsSinceEpoch()
                itemName = _('Today')
            elif tsDate >= week:
                endTs = QDateTime(week).toMSecsSinceEpoch()
                itemName = _('This Week')
            elif tsDate.month() == month.month() and tsDate.year(
            ) == month.year():
                endTs = QDateTime(month).toMSecsSinceEpoch()
                itemName = _('This Month')
            else:
                startDate = QDate(tsDate.year(), tsDate.month(),
                                  tsDate.daysInMonth())
                endDate = QDate(startDate.year(), startDate.month(), 1)

                ts = QDateTime(startDate, QTime(23, 59,
                                                59)).toMSecsSinceEpoch()
                endTs = QDateTime(endDate).toMSecsSinceEpoch()
                itemName = '%s %s' % (tsDate.year(),
                                      History.titleCaseLocalizedMonth(
                                          tsDate.month()))
            dbobj = HistoryDbModel.select().where(
                HistoryDbModel.date.between(endTs, ts)).first()
            if dbobj:
                item = HistoryItem(self._rootItem)
                item.setStartTimestamp(ts == currentTs and -1 or ts)
                item.setEndTimestamp(endTs)
                item.title = itemName
                item.canFetchMore = True

                if ts == currentTs:
                    self._todayItem = item

            ts = endTs - 1
コード例 #5
0
    def _deleteHistoryEntryByIndexList(self, list_):
        '''
        @param: list_ QList<int>
        '''

        dbobjs = list(HistoryDbModel.select().where(
            HistoryDbModel.id.in_(list_)))
        HistoryDbModel.delete().where(HistoryDbModel.id.in_(list_)).execute()
        urls = [QUrl(obj.url).toEncoded(QUrl.RemoveFragment) for obj in dbobjs]
        IconsDbModel.delete().where(IconsDbModel.url.in_(urls)).execute()
        for dbobj in dbobjs:
            entry = self.HistoryEntry.CreateFromDbobj(dbobj)
            self.historyEntryDeleted.emit(entry)
コード例 #6
0
    def createHistoryQuery(cls, searchString, limit, exactMatch=False):
        '''
        @param: searchString QString
        @param: limit int
        @param: exactMatch bool
        '''
        searchList = []  # QStringList
        qs = HistoryDbModel.select()
        if exactMatch:
            qs = qs.where(
                HistoryDbModel.title.contains(searchString)
                | HistoryDbModel.url.contains(searchString))
        else:
            searchList = [item.strip() for item in searchString.split(' ')]
            searchList = [item for item in searchList if item]
            conds = []
            for item in searchList:
                conds.append((HistoryDbModel.title.contains(item)
                              | HistoryDbModel.url.contains(item)))
            from peewee import operator
            from functools import reduce
            qs = qs.where(reduce(operator.and_, conds))

        qs = qs.order_by(HistoryDbModel.date.desc()).limit(limit)

        return qs
コード例 #7
0
    def fetchMore(self, parent):
        '''
        @param: parent QModelIndex
        '''
        from .History import HistoryEntry
        parentItem = self.itemFromIndex(parent)

        if not parent.isValid() or not parentItem:
            return

        parentItem.canFetchMore = False
        idList = []  # QList<int>
        for idx in range(parentItem.childCount()):
            idList.append(parentItem.child(idx).historyEntry.id)

        list_ = []  # QVector<HistoryEntry>

        dbobjs = HistoryDbModel.select().where(
            HistoryDbModel.date.between(parentItem.endTimestamp(),
                                        parentItem.startTimestamp()))
        for dbobj in dbobjs:
            entry = HistoryEntry.CreateFromDbobj(dbobj)
            if entry.id not in idList:
                list_.append(entry)

        if not list_:
            return

        self.beginInsertRows(parent, 0, len(list_) - 1)

        for entry in list_:
            newItem = HistoryItem(parentItem)
            newItem.historyEntry = entry

        self.endInsertRows()
コード例 #8
0
 def deleteHistoryEntryByUrl(self, url):
     '''
     @param: url QUrl
     '''
     items = HistoryDbModel.select(columns=['id']).where(
         HistoryDbModel.url == url).dicts()
     import ipdb
     ipdb.set_trace()
     ids = [item['id'] for item in dicts]
     self._deleteHistoryEntryByIndexList(ids)
コード例 #9
0
 def deleteHistoryEntryByUrlAndTitle(self, url, title):
     '''
     @param: url QUrl
     @param: title QString
     '''
     items = HistoryDbModel.select(columns=['id']).where(
         HistoryDbModel.url == url, HistoryDbModel.title == title).dicts()
     import ipdb
     ipdb.set_trace()
     ids = [item['id'] for item in dicts]
     self._deleteHistoryEntryByIndexList(ids)
コード例 #10
0
 def getHistoryEntry(self, text):
     '''
     @param: text QString
     '''
     dbobj = HistoryDbModel.select().where(
         HistoryDbModel.url == text).first()
     entry = self.HistoryEntry()
     if dbobj:
         entry.count = dbobj.count
         entry.date = QDateTime.fromMSecsSinceEpoch(entry.date)
         entry.id = dbobj.id
         entry.title = dbobj.title
         entry.url = QUrl(dbobj.url)
     return entry
コード例 #11
0
    def _completeMostVisited(self):
        qs = HistoryDbModel.select().order_by(
            HistoryDbModel.count.desc()).limit(15)
        for history in qs:
            item = QStandardItem()
            url = QUrl(history.url)

            item.setText(url.toEncoded().data().decode())
            item.setData(history.id, LocationCompleterModel.IdRole)
            item.setData(history.title, LocationCompleterModel.TitleRole)
            item.setData(url, LocationCompleterModel.UrlRole)
            item.setData(True, LocationCompleterModel.HistoryRole)

            self._items.append(item)
コード例 #12
0
    def indexesFromTimeRange(self, start, end):
        '''
        @param: start qint64
        @param: end qint64
        @return: QList<int>
        '''
        list_ = []  # QList<int>

        if start < 0 or end < 0:
            return list_

        ids = HistoryDbModel.select(HistoryDbModel.id, ).where(
            HistoryDbModel.date.between(end, start))
        list_ = [item for item in ids]
        return list_
コード例 #13
0
 def mostVisited(self, count):
     '''
     @param: count int
     @return: QVector<HistoryEntry>
     '''
     result = []
     for dbobj in HistoryDbModel.select().order_by(
             HistoryDbModel.count.desc()).limit(count):
         entry = self.HistoryEntry()
         entry.count = dbobj.count
         entry.date = QDateTime.fromMSecsSinceEpoch(dbobj.date)
         entry.id = dbobj.id
         entry.title = dbobj.title
         entry.url = QUrl(dbobj.url)
         result.append(entry)
     return result
コード例 #14
0
 def searchHistoryEntry(self, text):
     '''
     @param: text QString
     '''
     list_ = []  # QList<HistoryEntry>
     qs = HistoryDbModel.select().where(
         HistoryDbModel.title.contains(text)
         | HistoryDbModel.url.contains(text)).limit(50)
     for item in qs:
         entry = self.HistoryEntry()
         entry.count = item.count
         entry.date = QDateTime.fromMSecsSinceEpoch(item.date)
         entry.id = item.id
         entry.title = item.title
         entry.url = QUrl(item.url)
         list_.append(entry)
     return list_
コード例 #15
0
    def _clearOldIconsInDatabase(self):
        date = QDateTime.currentDateTime().addMonths(-6)

        urls = HistoryDbModel.select().where(
            HistoryDbModel.date < date.toMSecsSinceEpoch())
        IconsDbModel.delete().where(IconsDbModel.url.in_(urls)).execute()
コード例 #16
0
    def __init__(self, window, parent=None):
        '''
        @param: window BrowserWindow
        @param: parent QWidget
        '''
        super().__init__(parent)
        self._ui = uic.loadUi('mc/other/SiteInfoWidget.ui', self)
        self._window = window

        self.setAttribute(Qt.WA_DeleteOnClose)

        self.setPopupAlignment(Qt.AlignLeft)

        view = self._window.weView()

        self._ui.titleLabel.setText(_('<b>Site %s</b>') % view.url().host())

        if view.url().scheme() == 'https':
            self._ui.secureLabel.setText(
                _('Your connection to this site is <b>secured</b>.'))
            self._ui.secureIcon.setPixmap(
                QPixmap(':/icons/locationbar/safe.png'))
        else:
            self._ui.secureLabel.setText(
                _('Your connection to this site is <b>unsecured</b>'))
            self._ui.secureIcon.setPixmap(
                QPixmap(':/icons/locationbar/unsafe.png'))

        scheme = view.url().scheme()
        host = view.url().host()

        count = HistoryDbModel.select().where(
            HistoryDbModel.url.contains('%s://%s' % (scheme, host))).count()
        if count > 3:
            self._ui.historyLabel.setText(
                _('This is your <b>%s</b> visit of this site.') % count)
            self._ui.historyIcon.setPixmap(
                QPixmap(':/icons/locationbar/visit3.png'))
        elif count == 0:
            self._ui.historyLabel.setText(
                _('You have <b>never</b> visited this site before.'))
            self._ui.historyIcon.setPixmap(
                QPixmap(':/icons/locationbar/visit1.png'))
        else:
            self._ui.historyIcon.setPixmap(
                QPixmap(':/icons/locationbar/visit2.png'))
            text = ''
            if count == 1:
                text = _('first')
            elif count == 2:
                text = _('second')
            elif count == 3:
                text = _('third')
            self._ui.historyLabel.setText(
                _('This is your <b>%s</b> visit of this site.') % text)

        self._updateProtocolHandler()

        self._ui.pushButton.clicked.connect(
            self._window.action('Tools/SiteInfo').trigger)
        self._ui.protocolHandlerButton.clicked.connect(
            self._protocolHandlerButtonClicked)