diff --git a/src/lib/3rdparty/processinfo.cpp b/src/lib/3rdparty/processinfo.cpp new file mode 100644 index 000000000..452367314 --- /dev/null +++ b/src/lib/3rdparty/processinfo.cpp @@ -0,0 +1,113 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "processinfo.h" + +#ifdef Q_WS_X11 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#endif + +ProcessInfo::ProcessInfo(const QString &name) + : m_name(name) +{ +} + +bool ProcessInfo::isRunning() const +{ +#ifdef Q_WS_X11 + pid_t pid = GetPIDbyName(qPrintable(m_name)); + // -1 = process not found + // -2 = /proc fs access error + return (pid != -1 && pid != -2); +#else + return false; +#endif +} + +#ifdef Q_WS_X11 +bool ProcessInfo::IsNumeric(const char* ccharptr_CharacterList) const +{ + for (; *ccharptr_CharacterList; ccharptr_CharacterList++) { + if (*ccharptr_CharacterList < '0' || *ccharptr_CharacterList > '9') { + return false; + } + } + + return true; +} + +pid_t ProcessInfo::GetPIDbyName(const char* cchrptr_ProcessName) const +{ + char chrarry_CommandLinePath[100] ; + char chrarry_NameOfProcess[300] ; + char* chrptr_StringToCompare = NULL ; + pid_t pid_ProcessIdentifier = (pid_t) - 1 ; + struct dirent* de_DirEntity = NULL ; + DIR* dir_proc = NULL ; + + dir_proc = opendir("/proc/") ; + if (dir_proc == NULL) { + perror("Couldn't open the /proc/ directory") ; + return (pid_t) - 2 ; + } + + // Loop while not NULL + while ((de_DirEntity = readdir(dir_proc))) { + if (de_DirEntity->d_type == DT_DIR) { + if (IsNumeric(de_DirEntity->d_name)) { + strcpy(chrarry_CommandLinePath, "/proc/") ; + strcat(chrarry_CommandLinePath, de_DirEntity->d_name) ; + strcat(chrarry_CommandLinePath, "/cmdline") ; + FILE* fd_CmdLineFile = fopen(chrarry_CommandLinePath, "rt") ; // open the file for reading text + if (fd_CmdLineFile) { + fscanf(fd_CmdLineFile, "%20s", chrarry_NameOfProcess) ; // read from /proc//cmdline + fclose(fd_CmdLineFile); // close the file prior to exiting the routine + + if (strrchr(chrarry_NameOfProcess, '/')) { + chrptr_StringToCompare = strrchr(chrarry_NameOfProcess, '/') + 1 ; + } + else { + chrptr_StringToCompare = chrarry_NameOfProcess ; + } + + //printf("Process name: %s\n", chrarry_NameOfProcess); + //printf("Pure Process name: %s\n", chrptr_StringToCompare ); + + if (!strcmp(chrptr_StringToCompare, cchrptr_ProcessName)) { + pid_ProcessIdentifier = (pid_t) atoi(de_DirEntity->d_name) ; + closedir(dir_proc) ; + return pid_ProcessIdentifier ; + } + } + } + } + } + + closedir(dir_proc) ; + return pid_ProcessIdentifier ; +} + +#endif diff --git a/src/lib/3rdparty/processinfo.h b/src/lib/3rdparty/processinfo.h new file mode 100644 index 000000000..6becda2d5 --- /dev/null +++ b/src/lib/3rdparty/processinfo.h @@ -0,0 +1,47 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef PROCESSINFO_H +#define PROCESSINFO_H + +#include + +#include "qz_namespace.h" + +/* + * Code used from http://ubuntuforums.org/showpost.php?p=6593782&postcount=5 + * written by user WitchCraft + */ + +class QT_QUPZILLA_EXPORT ProcessInfo +{ +public: + explicit ProcessInfo(const QString &name); + + bool isRunning() const; + +private: +#ifdef Q_WS_X11 + bool IsNumeric(const char* ccharptr_CharacterList) const; + + pid_t GetPIDbyName(const char* cchrptr_ProcessName) const; +#endif + + QString m_name; +}; + +#endif // PROCESSINFO_H diff --git a/src/lib/adblock/adblockschemehandler.cpp b/src/lib/adblock/adblockschemehandler.cpp index ed86b9fdc..afb617f9a 100644 --- a/src/lib/adblock/adblockschemehandler.cpp +++ b/src/lib/adblock/adblockschemehandler.cpp @@ -55,7 +55,7 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat return 0; } - QString message = AdBlockManager::tr("Do you want to add %1 subscription?").arg(subscriptionTitle); + const QString &message = AdBlockManager::tr("Do you want to add %1 subscription?").arg(subscriptionTitle); QMessageBox::StandardButton result = QMessageBox::question(0, AdBlockManager::tr("AdBlock Subscription"), message, QMessageBox::Yes | QMessageBox::No); if (result == QMessageBox::Yes) { diff --git a/src/lib/data/icons.qrc b/src/lib/data/icons.qrc index d05a8ab13..bf432a452 100644 --- a/src/lib/data/icons.qrc +++ b/src/lib/data/icons.qrc @@ -17,13 +17,11 @@ qupzilla.png icons/locationbar/privatebrowsing.png icons/locationbar/unknownpage.png - icons/menu/google.png icons/menu/history.png icons/menu/history_entry.png icons/menu/popup.png icons/menu/qt.png icons/menu/rss.png - icons/menu/youtube.png icons/other/about.png icons/other/feed.png icons/other/progress.gif @@ -45,7 +43,6 @@ icons/other/adblock-disabled.png icons/menu/search-icon.png icons/menu/gear.png - icons/menu/wikipedia.png icons/browsers/firefox.png icons/browsers/chrome.png icons/browsers/opera.png @@ -58,9 +55,18 @@ icons/preferences/mail-inbox.png icons/preferences/preferences-system-firewall.png icons/browsers/html.png - icons/menu/translate.png - icons/menu/duck.png icons/exeicons/qupzilla-window.png icons/preferences/text-x-sql.png + icons/sites/akregator.png + icons/sites/aol.png + icons/sites/bloglines.png + icons/sites/duck.png + icons/sites/google.png + icons/sites/liferea.png + icons/sites/netvibes.png + icons/sites/translate.png + icons/sites/wikipedia.png + icons/sites/yahoo.png + icons/sites/youtube.png diff --git a/src/lib/data/icons/sites/akregator.png b/src/lib/data/icons/sites/akregator.png new file mode 100644 index 000000000..eb09f3e75 Binary files /dev/null and b/src/lib/data/icons/sites/akregator.png differ diff --git a/src/lib/data/icons/sites/aol.png b/src/lib/data/icons/sites/aol.png new file mode 100644 index 000000000..5c0997913 Binary files /dev/null and b/src/lib/data/icons/sites/aol.png differ diff --git a/src/lib/data/icons/sites/bloglines.png b/src/lib/data/icons/sites/bloglines.png new file mode 100644 index 000000000..d4a2b9963 Binary files /dev/null and b/src/lib/data/icons/sites/bloglines.png differ diff --git a/src/lib/data/icons/menu/duck.png b/src/lib/data/icons/sites/duck.png similarity index 100% rename from src/lib/data/icons/menu/duck.png rename to src/lib/data/icons/sites/duck.png diff --git a/src/lib/data/icons/menu/google.png b/src/lib/data/icons/sites/google.png similarity index 100% rename from src/lib/data/icons/menu/google.png rename to src/lib/data/icons/sites/google.png diff --git a/src/lib/data/icons/sites/liferea.png b/src/lib/data/icons/sites/liferea.png new file mode 100644 index 000000000..c123bcb80 Binary files /dev/null and b/src/lib/data/icons/sites/liferea.png differ diff --git a/src/lib/data/icons/sites/netvibes.png b/src/lib/data/icons/sites/netvibes.png new file mode 100644 index 000000000..948f765c6 Binary files /dev/null and b/src/lib/data/icons/sites/netvibes.png differ diff --git a/src/lib/data/icons/menu/translate.png b/src/lib/data/icons/sites/translate.png similarity index 100% rename from src/lib/data/icons/menu/translate.png rename to src/lib/data/icons/sites/translate.png diff --git a/src/lib/data/icons/menu/wikipedia.png b/src/lib/data/icons/sites/wikipedia.png similarity index 100% rename from src/lib/data/icons/menu/wikipedia.png rename to src/lib/data/icons/sites/wikipedia.png diff --git a/src/lib/data/icons/sites/yahoo.png b/src/lib/data/icons/sites/yahoo.png new file mode 100644 index 000000000..489d64647 Binary files /dev/null and b/src/lib/data/icons/sites/yahoo.png differ diff --git a/src/lib/data/icons/menu/youtube.png b/src/lib/data/icons/sites/youtube.png similarity index 100% rename from src/lib/data/icons/menu/youtube.png rename to src/lib/data/icons/sites/youtube.png diff --git a/src/lib/lib.pro b/src/lib/lib.pro index 5060bd85a..a13394da8 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -180,7 +180,8 @@ SOURCES += \ adblock/adblocktreewidget.cpp \ adblock/adblockaddsubscriptiondialog.cpp \ adblock/adblockschemehandler.cpp \ - tools/emptynetworkreply.cpp + tools/emptynetworkreply.cpp \ + 3rdparty/processinfo.cpp HEADERS += \ webview/tabpreview.h \ @@ -333,7 +334,8 @@ HEADERS += \ adblock/adblocktreewidget.h \ adblock/adblockaddsubscriptiondialog.h \ adblock/adblockschemehandler.h \ - tools/emptynetworkreply.h + tools/emptynetworkreply.h \ + 3rdparty/processinfo.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/lib/opensearch/searchenginesmanager.cpp b/src/lib/opensearch/searchenginesmanager.cpp index b98f677fd..b0f78f464 100644 --- a/src/lib/opensearch/searchenginesmanager.cpp +++ b/src/lib/opensearch/searchenginesmanager.cpp @@ -119,28 +119,28 @@ void SearchEnginesManager::restoreDefaults() { Engine google; google.name = "Google"; - google.icon = QIcon(":icons/menu/google.png"); + google.icon = QIcon(":icons/sites/google.png"); google.url = "http://www.google.com/search?client=qupzilla&q=%s"; google.shortcut = "g"; google.suggestionsUrl = "http://suggestqueries.google.com/complete/search?output=firefox&q=%s"; Engine wiki; wiki.name = "Wikipedia (en)"; - wiki.icon = QIcon(":/icons/menu/wikipedia.png"); + wiki.icon = QIcon(":/icons/sites/wikipedia.png"); wiki.url = "http://en.wikipedia.org/wiki/Special:Search?search=%s&fulltext=Search"; wiki.shortcut = "w"; wiki.suggestionsUrl = "http://en.wikipedia.org/w/api.php?action=opensearch&search=%s&namespace=0"; Engine yt; yt.name = "YouTube"; - yt.icon = QIcon(":/icons/menu/youtube.png"); + yt.icon = QIcon(":/icons/sites/youtube.png"); yt.url = "http://www.youtube.com/results?search_query=%s&search=Search"; yt.shortcut = "yt"; yt.suggestionsUrl = "http://suggestqueries.google.com/complete/search?ds=yt&output=firefox&q=%s"; Engine duck; duck.name = "DuckDuckGo"; - duck.icon = QIcon(":/icons/menu/duck.png"); + duck.icon = QIcon(":/icons/sites/duck.png"); duck.url = "https://duckduckgo.com/?q=%s&t=qupzilla"; duck.shortcut = "d"; diff --git a/src/lib/rss/rssnotification.cpp b/src/lib/rss/rssnotification.cpp index 8577aebd7..66d9a2347 100644 --- a/src/lib/rss/rssnotification.cpp +++ b/src/lib/rss/rssnotification.cpp @@ -18,24 +18,146 @@ #include "rssnotification.h" #include "ui_rssnotification.h" #include "mainapplication.h" -#include "qupzilla.h" +#include "browsinglibrary.h" #include "iconprovider.h" +#include "processinfo.h" +#include "rssmanager.h" +#include "settings.h" +#include "webview.h" -RSSNotification::RSSNotification(QString host, QWidget* parent) +#include +#include +#include +#include + +bool startExternalProcess(const QString &program, const QStringList &arguments) +{ + if (!QProcess::startDetached(program, arguments)) { + QString info = "
  • " + RSSNotification::tr("Executable: ") + "" + program + "
  • " + RSSNotification::tr("Arguments: ") + "" + arguments.join(" ") + "
"; + QMessageBox::critical(0, RSSNotification::tr("Cannot start external program"), RSSNotification::tr("Cannot start external program! %1").arg(info)); + + return false; + } + + return true; +} + +RSSNotification::RSSNotification(const QString &title, const QUrl &url, WebView* parent) : AnimatedWidget(AnimatedWidget::Down, 300, parent) , ui(new Ui::RSSNotification) + , m_title(title) + , m_url(url) + , m_view(parent) { setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(widget()); ui->closeButton->setIcon(qIconProvider->standardIcon(QStyle::SP_DialogCloseButton)); - ui->label->setText(QupZilla::tr("You have successfully added RSS feed \"%1\".").arg(host)); + ui->label->setText(tr("RSS feed \"%1\"").arg(title)); - connect(ui->pushButton, SIGNAL(clicked()), mApp->getWindow(), SLOT(showRSSManager())); - connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(hide())); + m_rssApps << RssApp("Bloglines", "http://www.bloglines.com/sub?url=", QIcon(":/icons/sites/bloglines.png")) + << RssApp("Google Reader", "http://www.google.com/ig/add?feedurl=", QIcon(":/icons/sites/google.png")) + << RssApp("My AOL", "http://feeds.my.aol.com/add.jsp?url=", QIcon(":/icons/sites/aol.png")) + << RssApp("Netvibes", "http://www.netvibes.com/subscribe.php?url=", QIcon(":/icons/sites/netvibes.png")) + << RssApp("Yahoo!", "http://add.my.yahoo.com/rss?url=", QIcon(":/icons/sites/yahoo.png")); + +#ifdef Q_WS_X11 + if (QFile("/usr/bin/akregator").exists()) { + m_rssApps << RssApp("Akregator", "/usr/bin/akregator -a ", QIcon(":/icons/sites/akregator.png"), DesktopApplication); + } + + if (QFile("/usr/bin/liferea").exists() && QFile("/usr/bin/liferea-add-feed").exists()) { + m_rssApps << RssApp("Liferea", "/usr/bin/liferea-add-feed ", QIcon(":/icons/sites/liferea.png"), DesktopApplication); + } +#endif + + foreach(const RssApp & app, m_rssApps) { + ui->comboBox->addItem(app.icon, app.title, QVariant(app.type)); + } + + ui->comboBox->addItem(QIcon(":/icons/qupzilla.png"), tr("Internal Reader"), QVariant(Internal)); + ui->comboBox->addItem(tr("Other..."), QVariant(Other)); + + Settings settings; + settings.beginGroup("RSS"); + ui->comboBox->setCurrentIndex(settings.value("LastAddOptionIndex", ui->comboBox->count() - 2).toInt()); + settings.endGroup(); + + connect(ui->add, SIGNAL(clicked()), this, SLOT(addRss())); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide())); + startAnimation(); } +void RSSNotification::hide() +{ + m_view->setFocus(); + AnimatedWidget::hide(); +} + +void RSSNotification::addRss() +{ + bool success = false; + int index = ui->comboBox->currentIndex(); + + switch (ui->comboBox->itemData(index).toInt()) { + case WebApplication: { + const RssApp &app = m_rssApps.at(index); + const QUrl &url = QUrl::fromEncoded(QString(app.address + QUrl::toPercentEncoding(m_url.toString())).toAscii()); + + m_view->openUrlInNewTab(url, Qz::NT_SelectedTab); + success = true; + break; + } + + case DesktopApplication: { + const RssApp &app = m_rssApps.at(index); + if (app.title == "Akregator") { + success = startExternalProcess("/usr/bin/akregator", QStringList() << "-a" << m_url.toEncoded()); + } + else if (app.title == "Liferea") { + if (!ProcessInfo("liferea").isRunning()) { + QMessageBox::warning(this, tr("Liferea not running"), tr("Liferea must be running in order to add new feed.")); + success = false; + } + else { + success = startExternalProcess("/usr/bin/liferea-add-feed", QStringList(m_url.toEncoded())); + } + } + break; + } + + case Other: { + QApplication::clipboard()->setText(m_url.toEncoded()); + const QString &message = tr("To add this RSS feed into other application, please use this information:

" + "Title: %1
Url: %2

" + "Url address of this feed has been copied into your clipboard.").arg(m_title, m_url.toString()); + QMessageBox::information(0, tr("Add feed into other application"), message); + success = true; + break; + } + + case Internal: + success = mApp->rssManager()->addRssFeed(m_url, m_title, m_view->icon()); + if (success) { + mApp->browsingLibrary()->showRSS(mApp->mainWindows().at(0)); + } + break; + + default: + break; + } + + if (success) { + Settings settings; + settings.beginGroup("RSS"); + settings.setValue("LastAddOptionIndex", index); + settings.endGroup(); + + hide(); + } +} + RSSNotification::~RSSNotification() { delete ui; diff --git a/src/lib/rss/rssnotification.h b/src/lib/rss/rssnotification.h index e3531c2ed..95cee3349 100644 --- a/src/lib/rss/rssnotification.h +++ b/src/lib/rss/rssnotification.h @@ -18,23 +18,55 @@ #ifndef RSSNOTIFICATION_H #define RSSNOTIFICATION_H +#include +#include + #include "qz_namespace.h" #include "animatedwidget.h" +class WebView; + namespace Ui { class RSSNotification; } -class AnimatedWidget; class QT_QUPZILLA_EXPORT RSSNotification : public AnimatedWidget { + Q_OBJECT public: - explicit RSSNotification(QString host, QWidget* parent = 0); + explicit RSSNotification(const QString &title, const QUrl &url, WebView* parent = 0); ~RSSNotification(); +public slots: + void hide(); + +private slots: + void addRss(); + private: + enum AppType { WebApplication, DesktopApplication, Internal, Other }; + struct RssApp { + QString title; + QString address; + QIcon icon; + AppType type; + + RssApp(const QString &t, const QString &a, const QIcon &i, AppType ty = WebApplication) { + title = t; + address = a; + icon = i; + type = ty; + } + }; + Ui::RSSNotification* ui; + + QString m_title; + QUrl m_url; + WebView* m_view; + + QList m_rssApps; }; #endif // RSSNOTIFICATION_H diff --git a/src/lib/rss/rssnotification.ui b/src/lib/rss/rssnotification.ui index cc68af172..ffd737100 100644 --- a/src/lib/rss/rssnotification.ui +++ b/src/lib/rss/rssnotification.ui @@ -38,6 +38,13 @@ + + + + + + + 0 @@ -45,14 +52,36 @@ - + Add this feed into + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + - Open RSS Manager + Add diff --git a/src/lib/rss/rsswidget.cpp b/src/lib/rss/rsswidget.cpp index 679018cb4..da4be9ba9 100644 --- a/src/lib/rss/rsswidget.cpp +++ b/src/lib/rss/rsswidget.cpp @@ -112,11 +112,9 @@ void RSSWidget::addRss() title = button->toolTip(); } - if (mApp->rssManager()->addRssFeed(url, title, m_view->icon())) { - RSSNotification* notif = new RSSNotification(title, m_view); - m_view->addNotification(notif); - close(); - } + RSSNotification* notif = new RSSNotification(title, url, m_view); + m_view->addNotification(notif); + close(); } } diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index baa9a7c81..5147ea52d 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -837,7 +837,7 @@ void WebView::createSelectedTextContextMenu(QMenu* menu, const QWebHitTestResult QString langCode = mApp->currentLanguage().left(2); QUrl googleTranslateUrl = QUrl(QString("http://translate.google.com/#auto|%1|%2").arg(langCode, selectedText)); - Action* gtwact = new Action(QIcon(":icons/menu/translate.png"), tr("Google Translate")); + Action* gtwact = new Action(QIcon(":icons/sites/translate.png"), tr("Google Translate")); gtwact->setData(googleTranslateUrl); connect(gtwact, SIGNAL(triggered()), this, SLOT(openUrlInSelectedTab())); connect(gtwact, SIGNAL(middleClicked()), this, SLOT(openUrlInBackgroundTab()));