From 3d9cd22bd28f87efe8cf51fcec59edf1d344c41e Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 26 Sep 2011 16:22:45 +0200 Subject: [PATCH 1/2] checking if internet is available before trying to check for an update. This resolve the shutdown after a minute error on mac os x and windows --- src/core/UBApplicationController.cpp | 32 ++- src/core/UBApplicationController.h | 3 + src/network/UBNetworkAccessManager.cpp | 323 ++++++++++++------------- 3 files changed, 188 insertions(+), 170 deletions(-) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 2ffc52c6..30783046 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -49,6 +49,8 @@ #include "podcast/UBPodcastController.h" +#include "network/UBNetworkAccessManager.h" + #include "ui_mainWindow.h" #ifdef Q_WS_MAC @@ -70,6 +72,7 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView, UBBo , mAutomaticCheckForUpdates(false) , mCheckingForUpdates(false) , mIsShowingDesktop(false) + , mHttp(0) { mDisplayManager = new UBDisplayManager(this); @@ -121,6 +124,7 @@ UBApplicationController::~UBApplicationController() delete mBlackScene; delete mMirror; if (mFtp) delete mFtp; + if (mHttp) delete mHttp; } @@ -499,17 +503,29 @@ void UBApplicationController::showSankoreEditor() emit mainModeChanged(mMainMode); } +void UBApplicationController::runCheckUpdate(int id, bool error) +{ + if(!error){ + if(mFtp!=NULL) + delete mFtp; + mFtp = new QFtp(this); + connect(mFtp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); + mFtp->connectToHost("91.121.248.138",21); + mFtp->login("anonymous", "anonymous"); + mFtp->get("update.json",0); + } +} void UBApplicationController::checkUpdate() { - if (mFtp!=NULL) - delete mFtp; - mFtp = new QFtp(this); - connect(mFtp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool))); - - mFtp->connectToHost("91.121.248.138",21); - mFtp->login("anonymous", "anonymous"); - mFtp->get("update.json",0); + //TODO change this when upgrade the qt version + // networkAccessible : NetworkAccessibility not yet available + if(mHttp) + delete mHttp; + QUrl url("http://www.google.com"); + mHttp = new QHttp(url.host()); + connect(mHttp, SIGNAL(requestFinished(int,bool)), this, SLOT(runCheckUpdate(int,bool))); + mHttp->get(url.path()); } void UBApplicationController::ftpCommandFinished(int id, bool error) diff --git a/src/core/UBApplicationController.h b/src/core/UBApplicationController.h index 75d6d3be..d0a224df 100644 --- a/src/core/UBApplicationController.h +++ b/src/core/UBApplicationController.h @@ -30,6 +30,7 @@ class UBVersion; class UBSoftwareUpdate; class QNetworkAccessManager; class QNetworkReply; +class QHttp; class UBApplicationController : public QObject @@ -135,6 +136,7 @@ class UBApplicationController : public QObject private slots: void ftpCommandFinished(int id, bool error); + void runCheckUpdate(int id, bool error); protected: @@ -171,6 +173,7 @@ class UBApplicationController : public QObject QNetworkAccessManager *networkAccessManager; void downloadJsonFinished(QString updateString); + QHttp* mHttp; }; #endif /* UBAPPLICATIONCONTROLLER_H_ */ diff --git a/src/network/UBNetworkAccessManager.cpp b/src/network/UBNetworkAccessManager.cpp index 5bcaf783..6529c388 100644 --- a/src/network/UBNetworkAccessManager.cpp +++ b/src/network/UBNetworkAccessManager.cpp @@ -12,165 +12,164 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "UBNetworkAccessManager.h" - -#include -#include - -#include "frameworks/UBDesktopServices.h" - -#include "core/UBApplication.h" -#include "core/UBApplicationController.h" -#include "core/UBSettings.h" - -#include "ui_passworddialog.h" -#include "ui_proxy.h" - -#include "UBCookieJar.h" - - -#include "core/memcheck.h" - -UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0; - -UBNetworkAccessManager *UBNetworkAccessManager::defaultAccessManager() -{ - if (!sNetworkAccessManager) { - sNetworkAccessManager = new UBNetworkAccessManager(qApp); - sNetworkAccessManager->setCookieJar(new UBCookieJar(sNetworkAccessManager)); - } - return sNetworkAccessManager; -} - -UBNetworkAccessManager::UBNetworkAccessManager(QObject *parent) - : QNetworkAccessManager(parent) - , mProxyAuthenticationCount(0) -{ - connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), - SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), - SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); - connect(this, SIGNAL(sslErrors(QNetworkReply*, const QList&)), - SLOT(sslErrors(QNetworkReply*, const QList&))); - - QNetworkProxy* proxy = UBSettings::settings()->httpProxy(); - - if (proxy) - { - setProxy(*proxy); - } - else - { - QNetworkProxyFactory::setUseSystemConfiguration(true); - } - - QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); - QString location = UBSettings::uniboardDataDirectory() + "/web-cache"; - diskCache->setCacheDirectory(location); - setCache(diskCache); -} - -QNetworkReply* UBNetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData) -{ - QNetworkRequest request = req; // copy so we can modify - // this is a temporary hack until we properly use the pipelining flags from QtWebkit - // pipeline everything! :) - request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); - - QNetworkReply* reply = QNetworkAccessManager::createRequest(op, request, outgoingData); - - return reply; -} - -QNetworkReply *UBNetworkAccessManager::get(const QNetworkRequest &request) -{ - qDebug() << "request url: " << request.url(); - QTime loadStartTime; - loadStartTime.start(); - QNetworkReply *networkReply = QNetworkAccessManager::get(request); - return networkReply; -} - -void UBNetworkAccessManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *auth) -{ - QWidget *mainWindow = QApplication::activeWindow(); - - QDialog dialog(mainWindow); - dialog.setWindowFlags(Qt::Sheet); - - Ui::PasswordDialog passwordDialog; - passwordDialog.setupUi(&dialog); - - passwordDialog.iconLabel->setText(QString()); - passwordDialog.iconLabel->setPixmap(mainWindow->style()->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mainWindow).pixmap(32, 32)); - - QString introMessage = tr("Enter username and password for \"%1\" at %2"); - introMessage = introMessage.arg(Qt::escape(reply->url().toString())).arg(Qt::escape(reply->url().toString())); - passwordDialog.introLabel->setText(introMessage); - passwordDialog.introLabel->setWordWrap(true); - - if (dialog.exec() == QDialog::Accepted) - { - if(auth && passwordDialog.userNameLineEdit) - auth->setUser(passwordDialog.userNameLineEdit->text()); - if(auth && passwordDialog.passwordLineEdit) - auth->setPassword(passwordDialog.passwordLineEdit->text()); - } - -} - -void UBNetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth) -{ - Q_UNUSED(proxy); - - QString username = UBSettings::settings()->proxyUsername(); - QString password = UBSettings::settings()->proxyPassword(); - - if (username.length() > 0 || password.length() > 0) - { - auth->setUser(username); - auth->setPassword(password); - } - - mProxyAuthenticationCount++; - - if (mProxyAuthenticationCount == 3) - { - UBApplication::showMessage(tr("Failed to log to Proxy")); - disconnect(SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)) - , this, SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); - - } - - return; - -} - -void UBNetworkAccessManager::sslErrors(QNetworkReply *reply, const QList &error) -{ - // check if SSL certificate has been trusted already - QString replyHost = reply->url().host() + ":" + reply->url().port(); - if(!sslTrustedHostList.contains(replyHost)) - { - QWidget *mainWindow = QApplication::activeWindow(); - - QStringList errorStrings; - for (int i = 0; i < error.count(); ++i) - errorStrings += error.at(i).errorString(); - - QString errors = errorStrings.join(QLatin1String("\n")); - - int ret = QMessageBox::warning(mainWindow, QCoreApplication::applicationName(), - tr("SSL Errors:\n\n%1\n\n%2\n\n" - "Do you want to ignore these errors for this host?").arg(reply->url().toString()).arg(errors), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No); - - if (ret == QMessageBox::Yes) - { - reply->ignoreSslErrors(); - sslTrustedHostList.append(replyHost); - } - } -} - +#include "UBNetworkAccessManager.h" + +#include +#include + +#include "frameworks/UBDesktopServices.h" + +#include "core/UBApplication.h" +#include "core/UBApplicationController.h" +#include "core/UBSettings.h" + +#include "ui_passworddialog.h" +#include "ui_proxy.h" + +#include "UBCookieJar.h" + + +#include "core/memcheck.h" + +UBNetworkAccessManager *UBNetworkAccessManager::sNetworkAccessManager = 0; + +UBNetworkAccessManager *UBNetworkAccessManager::defaultAccessManager() +{ + if (!sNetworkAccessManager) { + sNetworkAccessManager = new UBNetworkAccessManager(qApp); + sNetworkAccessManager->setCookieJar(new UBCookieJar(sNetworkAccessManager)); + } + return sNetworkAccessManager; +} + +UBNetworkAccessManager::UBNetworkAccessManager(QObject *parent) + : QNetworkAccessManager(parent) + , mProxyAuthenticationCount(0) +{ + connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), + SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); + connect(this, SIGNAL(sslErrors(QNetworkReply*, const QList&)), + SLOT(sslErrors(QNetworkReply*, const QList&))); + + QNetworkProxy* proxy = UBSettings::settings()->httpProxy(); + + if (proxy) + { + setProxy(*proxy); + } + else + { + QNetworkProxyFactory::setUseSystemConfiguration(true); + } + + QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); + QString location = UBSettings::uniboardDataDirectory() + "/web-cache"; + diskCache->setCacheDirectory(location); + setCache(diskCache); +} + +QNetworkReply* UBNetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData) +{ + QNetworkRequest request = req; // copy so we can modify + // this is a temporary hack until we properly use the pipelining flags from QtWebkit + // pipeline everything! :) + request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + + QNetworkReply* reply = QNetworkAccessManager::createRequest(op, request, outgoingData); + + return reply; +} + +QNetworkReply *UBNetworkAccessManager::get(const QNetworkRequest &request) +{ + qDebug() << "request url: " << request.url(); + QTime loadStartTime; + loadStartTime.start(); + QNetworkReply *networkReply = QNetworkAccessManager::get(request); + return networkReply; +} + +void UBNetworkAccessManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *auth) +{ + QWidget *mainWindow = QApplication::activeWindow(); + + QDialog dialog(mainWindow); + dialog.setWindowFlags(Qt::Sheet); + + Ui::PasswordDialog passwordDialog; + passwordDialog.setupUi(&dialog); + + passwordDialog.iconLabel->setText(QString()); + passwordDialog.iconLabel->setPixmap(mainWindow->style()->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mainWindow).pixmap(32, 32)); + + QString introMessage = tr("Enter username and password for \"%1\" at %2"); + introMessage = introMessage.arg(Qt::escape(reply->url().toString())).arg(Qt::escape(reply->url().toString())); + passwordDialog.introLabel->setText(introMessage); + passwordDialog.introLabel->setWordWrap(true); + + if (dialog.exec() == QDialog::Accepted) + { + if(auth && passwordDialog.userNameLineEdit) + auth->setUser(passwordDialog.userNameLineEdit->text()); + if(auth && passwordDialog.passwordLineEdit) + auth->setPassword(passwordDialog.passwordLineEdit->text()); + } + +} + +void UBNetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth) +{ + Q_UNUSED(proxy); + + QString username = UBSettings::settings()->proxyUsername(); + QString password = UBSettings::settings()->proxyPassword(); + + if (username.length() > 0 || password.length() > 0) + { + auth->setUser(username); + auth->setPassword(password); + } + + mProxyAuthenticationCount++; + + if (mProxyAuthenticationCount == 3) + { + UBApplication::showMessage(tr("Failed to log to Proxy")); + disconnect(SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)) + , this, SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); + + } + + return; + +} + +void UBNetworkAccessManager::sslErrors(QNetworkReply *reply, const QList &error) +{ + // check if SSL certificate has been trusted already + QString replyHost = reply->url().host() + ":" + reply->url().port(); + if(!sslTrustedHostList.contains(replyHost)) + { + QWidget *mainWindow = QApplication::activeWindow(); + + QStringList errorStrings; + for (int i = 0; i < error.count(); ++i) + errorStrings += error.at(i).errorString(); + + QString errors = errorStrings.join(QLatin1String("\n")); + + int ret = QMessageBox::warning(mainWindow, QCoreApplication::applicationName(), + tr("SSL Errors:\n\n%1\n\n%2\n\n" + "Do you want to ignore these errors for this host?").arg(reply->url().toString()).arg(errors), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); + + if (ret == QMessageBox::Yes) + { + reply->ignoreSslErrors(); + sslTrustedHostList.append(replyHost); + } + } +} From c0089c9feba243d4e0847b2bb3f78cdba3f11ab0 Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Mon, 26 Sep 2011 19:47:17 +0300 Subject: [PATCH 2/2] issue Sankore-165 resolved --- src/board/UBLibraryController.cpp | 7 ++++++- src/board/UBLibraryController.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index 28b8008a..9a7e1c9c 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -72,7 +72,9 @@ UBLibraryController::UBLibraryController(QWidget *pParentWidget) : bool UBLibraryController::canItemsOnElementBeDeleted(UBLibElement *pElement) { - return !pElement->path().toLocalFile().startsWith(UBSettings::settings()->uniboardShapeLibraryDirectory()); + return !pElement->path().toLocalFile().startsWith(UBSettings::settings()->uniboardShapeLibraryDirectory()) && + !pElement->path().toLocalFile().startsWith(UBSettings::settings()->sankoreDistributedInteractiveDirectory()) && + pElement->isDeletable(); } void UBLibraryController::createInternalWidgetItems() @@ -696,6 +698,7 @@ UBLibElement::UBLibElement() { mType = eUBLibElementType_Category; mName = QObject::tr("/Home", "Category list label on navigation tool bar"); mbMoveable = false; + mbDeletable = true; } UBLibElement::UBLibElement(UBLibElement* element) @@ -707,6 +710,7 @@ UBLibElement::UBLibElement(UBLibElement* element) mName = element->name(); mExtension = element->extension(); mbMoveable = element->isMoveable(); + mbDeletable = element->isDeletable(); } @@ -717,6 +721,7 @@ UBLibElement::UBLibElement(eUBLibElementType type, const QUrl &path, const QStri mName = name; mInfo = ""; mbMoveable = true; + mbDeletable = true; if (type == eUBLibElementType_Folder) mThumbnail = QImage(":images/libpalette/folder.svg"); diff --git a/src/board/UBLibraryController.h b/src/board/UBLibraryController.h index 26b6fe61..009114ef 100644 --- a/src/board/UBLibraryController.h +++ b/src/board/UBLibraryController.h @@ -61,6 +61,8 @@ public: void setExtension(QString &extension){ mExtension = extension;} bool isMoveable(){return mbMoveable;} void setMoveable(bool bState){mbMoveable = bState;} + bool isDeletable() const {return mbDeletable;} + void setDeletable(bool mState) {mbDeletable = mState;} private: eUBLibElementType mType; @@ -70,6 +72,7 @@ private: QString mName; QString mExtension; bool mbMoveable; + bool mbDeletable; }; class UBChainedLibElement