1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-14 02:52:12 +01:00

[win] Don't check for default browser on startup.

Also cleanup in #ifdefs in RegisterQappAssociation
This commit is contained in:
nowrep 2013-01-29 20:34:14 +01:00
parent b415df3395
commit 95445738ef
6 changed files with 33 additions and 206 deletions

View File

@ -50,6 +50,7 @@
#include "useragentmanager.h" #include "useragentmanager.h"
#include "restoremanager.h" #include "restoremanager.h"
#include "proxystyle.h" #include "proxystyle.h"
#include "checkboxdialog.h"
#include "registerqappassociation.h" #include "registerqappassociation.h"
#include "html5permissions/html5permissionsmanager.h" #include "html5permissions/html5permissionsmanager.h"
@ -95,7 +96,9 @@ MainApplication::MainApplication(int &argc, char** argv)
, m_isRestoring(false) , m_isRestoring(false)
, m_startingAfterCrash(false) , m_startingAfterCrash(false)
, m_databaseConnected(false) , m_databaseConnected(false)
#ifdef Q_OS_WIN
, m_registerQAppAssociation(0) , m_registerQAppAssociation(0)
#endif
{ {
#if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH) #if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH)
DATADIR = USE_DATADIR; DATADIR = USE_DATADIR;
@ -836,22 +839,29 @@ void MainApplication::reloadUserStyleSheet()
bool MainApplication::checkDefaultWebBrowser() bool MainApplication::checkDefaultWebBrowser()
{ {
#ifdef Q_OS_WIN
bool showAgain = true; bool showAgain = true;
if (!associationManager()->isDefaultForAllCapabilities()) { if (!associationManager()->isDefaultForAllCapabilities()) {
CheckMessageBox notDefaultDialog(&showAgain, getWindow()); CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, this);
notDefaultDialog.setWindowTitle(tr("Default Browser")); dialog.setText(tr("QupZilla is not currently your default browser. Would you like to make it your default browser?"));
notDefaultDialog.setMessage(tr("QupZilla is not currently your default browser. Would you like to make it your default browser?")); dialog.setCheckBoxText(tr("Always perform this check when starting QupZilla."));
notDefaultDialog.setPixmap(style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(32, 32)); dialog.setWindowTitle(tr("Default Browser"));
notDefaultDialog.setShowAgainText(tr("Always perform this check when starting QupZilla.")); dialog.setIcon(qIconProvider->standardIcon(QStyle::SP_MessageBoxWarning));
if (notDefaultDialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
associationManager()->registerAllAssociation(); associationManager()->registerAllAssociation();
} }
showAgain = dialog.isChecked();
} }
return showAgain; return showAgain;
#else
return false;
#endif
} }
#ifdef Q_OS_WIN
RegisterQAppAssociation* MainApplication::associationManager() RegisterQAppAssociation* MainApplication::associationManager()
{ {
if (!m_registerQAppAssociation) { if (!m_registerQAppAssociation) {
@ -867,6 +877,7 @@ RegisterQAppAssociation* MainApplication::associationManager()
} }
return m_registerQAppAssociation; return m_registerQAppAssociation;
} }
#endif
QUrl MainApplication::userStyleSheet(const QString &filePath) const QUrl MainApplication::userStyleSheet(const QString &filePath) const
{ {

View File

@ -111,7 +111,10 @@ public:
DatabaseWriter* dbWriter() { return m_dbWriter; } DatabaseWriter* dbWriter() { return m_dbWriter; }
UserAgentManager* uaManager() { return m_uaManager; } UserAgentManager* uaManager() { return m_uaManager; }
RestoreManager* restoreManager() { return m_restoreManager; } RestoreManager* restoreManager() { return m_restoreManager; }
#ifdef Q_OS_WIN
RegisterQAppAssociation* associationManager(); RegisterQAppAssociation* associationManager();
#endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
bool event(QEvent* e); bool event(QEvent* e);
@ -182,7 +185,9 @@ private:
bool m_databaseConnected; bool m_databaseConnected;
QList<PostLaunchAction> m_postLaunchActions; QList<PostLaunchAction> m_postLaunchActions;
#ifdef Q_OS_WIN
RegisterQAppAssociation* m_registerQAppAssociation; RegisterQAppAssociation* m_registerQAppAssociation;
#endif
}; };
#endif // MAINAPPLICATION_H #endif // MAINAPPLICATION_H

View File

@ -104,12 +104,12 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags)
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#define DEFAULT_CHECK_UPDATES true #define DEFAULT_CHECK_UPDATES true
#define DEFAULT_CHECK_DEFAULTBROWSER true
#else #else
#define DEFAULT_CHECK_UPDATES false #define DEFAULT_CHECK_UPDATES false
#define DEFAULT_CHECK_DEFAULTBROWSER false
#endif #endif
#define DEFAULT_CHECK_DEFAULTBROWSER false
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG false #define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG false
#else #else

View File

@ -1,5 +1,5 @@
/* ============================================================ /* ============================================================
* Copyright (C) 2012 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com> * Copyright (C) 2012-2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* This file is part of QupZilla - WebKit based browser 2010-2012 * This file is part of QupZilla - WebKit based browser 2010-2012
* by David Rosca <nowrep@gmail.com> * by David Rosca <nowrep@gmail.com>
* *
@ -22,8 +22,6 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "ShlObj.h" #include "ShlObj.h"
#include <QMessageBox> #include <QMessageBox>
#endif
#include <QStringList> #include <QStringList>
#include <QSettings> #include <QSettings>
#include <QDir> #include <QDir>
@ -80,28 +78,19 @@ void RegisterQAppAssociation::setAppInfo(const QString &appRegisteredName, const
bool RegisterQAppAssociation::isPerMachineRegisteration() bool RegisterQAppAssociation::isPerMachineRegisteration()
{ {
#ifdef Q_OS_WIN
return (_UserRootKey == "HKEY_LOCAL_MACHINE"); return (_UserRootKey == "HKEY_LOCAL_MACHINE");
#else
return false;
#endif
} }
void RegisterQAppAssociation::setPerMachineRegisteration(bool enable) void RegisterQAppAssociation::setPerMachineRegisteration(bool enable)
{ {
#ifdef Q_OS_WIN
if (enable) { if (enable) {
_UserRootKey = "HKEY_LOCAL_MACHINE"; _UserRootKey = "HKEY_LOCAL_MACHINE";
} }
else { else {
_UserRootKey = "HKEY_CURRENT_USER"; _UserRootKey = "HKEY_CURRENT_USER";
} }
#else
Q_UNUSED(enable)
#endif
} }
#ifdef Q_OS_WIN
bool RegisterQAppAssociation::registerAppCapabilities() bool RegisterQAppAssociation::registerAppCapabilities()
{ {
if (!isVistaOrNewer()) { if (!isVistaOrNewer()) {
@ -157,11 +146,9 @@ bool RegisterQAppAssociation::isVistaOrNewer()
return (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA && return (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA &&
QSysInfo::windowsVersion() <= QSysInfo::WV_NT_based); QSysInfo::windowsVersion() <= QSysInfo::WV_NT_based);
} }
#endif
void RegisterQAppAssociation::registerAssociation(const QString &assocName, AssociationType type) void RegisterQAppAssociation::registerAssociation(const QString &assocName, AssociationType type)
{ {
#ifdef Q_OS_WIN
if (isVistaOrNewer()) { // Vista and newer if (isVistaOrNewer()) { // Vista and newer
IApplicationAssociationRegistration* pAAR; IApplicationAssociationRegistration* pAAR;
@ -239,19 +226,13 @@ void RegisterQAppAssociation::registerAssociation(const QString &assocName, Asso
} }
regUserRoot.endGroup(); regUserRoot.endGroup();
} }
#else
Q_UNUSED(assocName)
Q_UNUSED(type)
#endif
} }
void RegisterQAppAssociation::registerAllAssociation() void RegisterQAppAssociation::registerAllAssociation()
{ {
#ifdef Q_OS_WIN
if (isVistaOrNewer() && !registerAppCapabilities()) { if (isVistaOrNewer() && !registerAppCapabilities()) {
return; return;
} }
#endif
QHash<QString, QString>::const_iterator i = _fileAssocHash.constBegin(); QHash<QString, QString>::const_iterator i = _fileAssocHash.constBegin();
while (i != _fileAssocHash.constEnd()) { while (i != _fileAssocHash.constEnd()) {
@ -265,18 +246,15 @@ void RegisterQAppAssociation::registerAllAssociation()
++i; ++i;
} }
#ifdef Q_OS_WIN
if (!isVistaOrNewer()) { if (!isVistaOrNewer()) {
// On Windows Vista or newer for updating icons 'pAAR->SetAppAsDefault()' // On Windows Vista or newer for updating icons 'pAAR->SetAppAsDefault()'
// calls 'SHChangeNotify()'. Thus, we just need care about older Windows. // calls 'SHChangeNotify()'. Thus, we just need care about older Windows.
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, 0 , 0); SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, 0 , 0);
} }
#endif
} }
void RegisterQAppAssociation::createProgId(const QString &progId) void RegisterQAppAssociation::createProgId(const QString &progId)
{ {
#ifdef Q_OS_WIN
QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat); QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat);
regUserRoot.beginGroup("Software/Classes"); regUserRoot.beginGroup("Software/Classes");
QPair<QString, QString> pair = _assocDescHash.value(progId); QPair<QString, QString> pair = _assocDescHash.value(progId);
@ -285,14 +263,10 @@ void RegisterQAppAssociation::createProgId(const QString &progId)
regUserRoot.setValue(progId + "/DefaultIcon/.", pair.second); regUserRoot.setValue(progId + "/DefaultIcon/.", pair.second);
regUserRoot.setValue(progId + "/shell/open/command/.", QString("\"" + _appPath + "\" \"%1\"")); regUserRoot.setValue(progId + "/shell/open/command/.", QString("\"" + _appPath + "\" \"%1\""));
regUserRoot.endGroup(); regUserRoot.endGroup();
#else
Q_UNUSED(progId)
#endif
} }
bool RegisterQAppAssociation::isDefaultApp(const QString &assocName, AssociationType type) bool RegisterQAppAssociation::isDefaultApp(const QString &assocName, AssociationType type)
{ {
#ifdef Q_OS_WIN
if (isVistaOrNewer()) { if (isVistaOrNewer()) {
QSettings regCurrentUserRoot("HKEY_CURRENT_USER", QSettings::NativeFormat); QSettings regCurrentUserRoot("HKEY_CURRENT_USER", QSettings::NativeFormat);
switch (type) { switch (type) {
@ -351,10 +325,7 @@ bool RegisterQAppAssociation::isDefaultApp(const QString &assocName, Association
break; break;
} }
} }
#else
Q_UNUSED(assocName)
Q_UNUSED(type)
#endif
return false; return false;
} }
@ -376,124 +347,4 @@ bool RegisterQAppAssociation::isDefaultForAllCapabilities()
} }
return result; return result;
} }
#endif
/***************************************/
/******** CheckMessageBox Class ********/
/***************************************/
CheckMessageBox::CheckMessageBox(bool* defaultShowAgainState, QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f | Qt::MSWindowsFixedSizeDialogHint),
_showAgainState(defaultShowAgainState)
{
setupUi();
if (defaultShowAgainState) {
showAgainCheckBox->setChecked(*defaultShowAgainState);
}
else {
showAgainCheckBox->hide();
disconnect(showAgainCheckBox, SIGNAL(toggled(bool)), this, SLOT(showAgainStateChanged(bool)));
}
}
CheckMessageBox::CheckMessageBox(const QString &msg, const QPixmap &pixmap,
const QString &str, bool* defaultShowAgainState,
QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f | Qt::MSWindowsFixedSizeDialogHint),
_showAgainState(defaultShowAgainState)
{
setupUi();
setMessage(msg);
setPixmap(pixmap);
if (defaultShowAgainState) {
setShowAgainText(str);
}
}
CheckMessageBox::~CheckMessageBox()
{
}
void CheckMessageBox::setMessage(const QString &msg)
{
messageLabel->setText(msg);
}
void CheckMessageBox::setShowAgainText(const QString &str)
{
showAgainCheckBox->setText(str);
}
void CheckMessageBox::setPixmap(const QPixmap &pixmap)
{
pixmapLabel->setPixmap(pixmap);
}
void CheckMessageBox::setupUi()
{
setObjectName(QString::fromUtf8("CheckMessageBox"));
gridLayout = new QGridLayout(this);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
verticalLayout_2 = new QVBoxLayout();
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
pixmapLabel = new QLabel(this);
pixmapLabel->setObjectName(QString::fromUtf8("pixmapLabel"));
verticalLayout_2->addWidget(pixmapLabel);
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_2->addItem(verticalSpacer);
horizontalLayout->addLayout(verticalLayout_2);
verticalLayout = new QVBoxLayout();
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
messageLabel = new QLabel(this);
messageLabel->setObjectName(QString::fromUtf8("messageLabel"));
messageLabel->setWordWrap(true);
verticalLayout->addWidget(messageLabel);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
verticalLayout->addItem(horizontalSpacer);
showAgainCheckBox = new QCheckBox(this);
showAgainCheckBox->setObjectName(QString::fromUtf8("showAgainCheckBox"));
verticalLayout->addWidget(showAgainCheckBox);
horizontalLayout->addLayout(verticalLayout);
gridLayout->addLayout(horizontalLayout, 0, 0, 1, 1);
buttonBox = new QDialogButtonBox(this);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::No | QDialogButtonBox::Yes);
gridLayout->addWidget(buttonBox, 1, 0, 1, 1);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
if (_showAgainState) {
showAgainCheckBox->setChecked(*_showAgainState);
connect(showAgainCheckBox, SIGNAL(toggled(bool)), this, SLOT(showAgainStateChanged(bool)));
}
else {
showAgainCheckBox->hide();
}
}
void CheckMessageBox::showAgainStateChanged(bool checked)
{
if (_showAgainState) {
*_showAgainState = checked;
}
}

View File

@ -1,5 +1,5 @@
/* ============================================================ /* ============================================================
* Copyright (C) 2012 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com> * Copyright (C) 2012-2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* This file is part of QupZilla - WebKit based browser 2010-2012 * This file is part of QupZilla - WebKit based browser 2010-2012
* by David Rosca <nowrep@gmail.com> * by David Rosca <nowrep@gmail.com>
* *
@ -25,6 +25,8 @@
#include "qz_namespace.h" #include "qz_namespace.h"
#ifdef Q_OS_WIN
class QT_QUPZILLA_EXPORT RegisterQAppAssociation : public QObject class QT_QUPZILLA_EXPORT RegisterQAppAssociation : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -48,10 +50,8 @@ public:
bool isPerMachineRegisteration(); bool isPerMachineRegisteration();
void setPerMachineRegisteration(bool enable); void setPerMachineRegisteration(bool enable);
#ifdef Q_OS_WIN
bool registerAppCapabilities(); bool registerAppCapabilities();
bool isVistaOrNewer(); bool isVistaOrNewer();
#endif
void registerAssociation(const QString &assocName, AssociationType type); void registerAssociation(const QString &assocName, AssociationType type);
void createProgId(const QString &progId); void createProgId(const QString &progId);
@ -65,52 +65,12 @@ private:
QString _appPath; QString _appPath;
QString _appIcon; QString _appIcon;
QString _appDesc; QString _appDesc;
#ifdef Q_OS_WIN
QString _UserRootKey; QString _UserRootKey;
#endif
QHash<QString, QString> _fileAssocHash; // (extention, progId) QHash<QString, QString> _fileAssocHash; // (extention, progId)
QHash<QString, QString> _urlAssocHash; // (protocol, progId) QHash<QString, QString> _urlAssocHash; // (protocol, progId)
QHash<QString, QPair<QString, QString> > _assocDescHash; // (progId, (desc, icon)) QHash<QString, QPair<QString, QString> > _assocDescHash; // (progId, (desc, icon))
}; };
#endif
#include <QDialog>
#include <QLabel>
#include <QGridLayout>
#include <QCheckBox>
#include <QDialogButtonBox>
class QT_QUPZILLA_EXPORT CheckMessageBox : public QDialog
{
Q_OBJECT
public:
CheckMessageBox(bool* defaultShowAgainState = 0, QWidget* parent = 0, Qt::WindowFlags f = 0);
CheckMessageBox(const QString &msg, const QPixmap &pixmap,
const QString &str, bool* defaultShowAgainState,
QWidget* parent = 0, Qt::WindowFlags f = 0);
~CheckMessageBox();
void setMessage(const QString &msg);
void setShowAgainText(const QString &str);
void setPixmap(const QPixmap &pixmap);
private:
void setupUi();
bool* _showAgainState;
QGridLayout* gridLayout;
QHBoxLayout* horizontalLayout;
QVBoxLayout* verticalLayout_2;
QLabel* pixmapLabel;
QSpacerItem* verticalSpacer;
QVBoxLayout* verticalLayout;
QLabel* messageLabel;
QSpacerItem* horizontalSpacer;
QCheckBox* showAgainCheckBox;
QDialogButtonBox* buttonBox;
private slots:
void showAgainStateChanged(bool checked);
};
#endif // REGISTERQAPPASSOCIATION_H #endif // REGISTERQAPPASSOCIATION_H