diff options
Diffstat (limited to 'src/previewimage.cpp')
-rw-r--r-- | src/previewimage.cpp | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/src/previewimage.cpp b/src/previewimage.cpp index 03741770..f1823629 100644 --- a/src/previewimage.cpp +++ b/src/previewimage.cpp @@ -58,7 +58,7 @@ PreviewImage::PreviewImage(const QUrl &url, int index, bool isFavorite) , m_isFavorite(isFavorite) , m_index(index) , m_button(0) -{ +{ loadUrlPreview(url); } @@ -73,15 +73,15 @@ PreviewImage::~PreviewImage() void PreviewImage::loadUrlPreview(const QUrl& url) { m_url = url; - + if(url.isEmpty()) { showEmptyPreview(); return; } - + m_savePath = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true); - + if(QFile::exists(m_savePath)) { m_pixmap.load(m_savePath); @@ -92,9 +92,9 @@ void PreviewImage::loadUrlPreview(const QUrl& url) loadingSnapshot = true; ws = new WebSnap( url ); connect(ws, SIGNAL(finished()), this, SLOT(snapFinished())); - + QString path = KStandardDirs::locate("appdata", "pics/busywidget.gif"); - + // load an animation waiting for site preview QMovie *movie = new QMovie(path, QByteArray(), this); movie->setSpeed(50); @@ -110,26 +110,26 @@ void PreviewImage::snapFinished() QMovie *m = movie(); delete m; setMovie(0); - + m_pixmap = ws->previewImage(); setPixmap(m_pixmap); m_pixmap.save(m_savePath); - + if(m_index > -1) { // Update title QStringList names = ReKonfig::previewNames(); // update url (for added thumbs) QStringList urls = ReKonfig::previewUrls(); - + // stripTrailingSlash to be sure to get the same string for same adress urls.replace(m_index, ws->snapUrl().toString(QUrl::StripTrailingSlash)); names.replace(m_index, ws->snapTitle()); - + ReKonfig::setPreviewNames(names); ReKonfig::setPreviewUrls(urls); - + ReKonfig::self()->writeConfig(); } } @@ -139,9 +139,9 @@ void PreviewImage::showEmptyPreview() { if(!m_isFavorite) return; - + clear(); - + QHBoxLayout *layout = new QHBoxLayout(this); m_button = new QToolButton(this); m_button->setDefaultAction(historyMenu()); @@ -172,21 +172,24 @@ void PreviewImage::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { - if(m_isFavorite) - { + // if(m_isFavorite) + // { Application::instance()->loadUrl(m_url); - } + + //TODO: what is that ? : + /* } else { MainView *mv = Application::instance()->mainWindow()->mainView(); int actualIndex = mv->currentIndex(); - + kDebug() << "Actual index: " << actualIndex; kDebug() << "m_index: " << m_index; mv->slotCloseTab(actualIndex); mv->setCurrentIndex(m_index); } + */ return; }; QLabel::mousePressEvent(event); @@ -198,31 +201,31 @@ void PreviewImage::mouseReleaseEvent(QMouseEvent *event) kDebug() << "NO000... don't leave your finger from the button!!"; Q_UNUSED(event) } - + void PreviewImage::contextMenuEvent(QContextMenuEvent* event) { if(!m_isFavorite) return; - + if(loadingSnapshot) return; - + KMenu menu(this); KAction *a; - + if(!m_url.isEmpty()) { a = new KAction(KIcon("edit-delete"), i18n("Remove Thumbnail"), this); connect(a, SIGNAL(triggered(bool)), this, SLOT(removeMe())); menu.addAction(a); - + a = new KAction(KIcon("view-refresh"), i18n("Refresh Thumbnail"), &menu); connect(a, SIGNAL(triggered(bool)), this, SLOT(refreshPreview())); menu.addAction(a); } menu.addAction(historyMenu()); - + menu.exec(mapToGlobal(event->pos())); } @@ -231,7 +234,7 @@ KActionMenu* PreviewImage::historyMenu() { KActionMenu *histMenu = new KActionMenu(KIcon("insert-image"), i18n("Set page to preview"), this); QList<HistoryItem> history = Application::historyManager()->history(); - + if(history.isEmpty()) { KAction *a = new KAction(i18n("History is empty"), this); @@ -239,7 +242,7 @@ KActionMenu* PreviewImage::historyMenu() histMenu->addAction(a); return histMenu; } - + int maxItems = 15; for (int i = 0; i < maxItems && i < history.size() ; ++i) { @@ -249,7 +252,7 @@ KActionMenu* PreviewImage::historyMenu() connect(a, SIGNAL(triggered(bool)), this, SLOT(setUrlFromAction())); histMenu->addAction(a); } - + return histMenu; } @@ -258,20 +261,20 @@ void PreviewImage::removeMe() { QStringList names = ReKonfig::previewNames(); QStringList urls = ReKonfig::previewUrls(); - + int index = urls.indexOf(QRegExp(m_url.toString(QUrl::StripTrailingSlash), Qt::CaseSensitive, QRegExp::FixedString)); urls.replace(index, QString("")); names.replace(index, QString("")); - + ReKonfig::setPreviewNames(names); ReKonfig::setPreviewUrls(urls); - + // sync file data ReKonfig::self()->writeConfig(); showEmptyPreview(); - + m_url = ""; } @@ -280,13 +283,13 @@ void PreviewImage::setUrlFromAction() { KAction *a = qobject_cast<KAction*>(sender()); KUrl url = KUrl(a->data().toString()); - + if(m_button) { layout()->deleteLater(); m_button->menu()->deleteLater(); m_button->deleteLater(); - } + } loadUrlPreview(url); } @@ -313,6 +316,6 @@ QString PreviewImage::guessNameFromUrl(QUrl url) name.remove('?'); name.remove('='); name.remove('+'); - + return name; } |