Commit a8420b2a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Rename DiscoverMainWindow to DiscoverObject

It's not the main window anymore
parent 9b9a2991
......@@ -8,7 +8,7 @@ qt5_add_resources(plasma_discover_SRCS assets.qrc)
add_executable(plasma-discover ${plasma_discover_SRCS}
main.cpp
DiscoverMainWindow.cpp
DiscoverObject.cpp
DiscoverDeclarativePlugin.cpp
FeaturedModel.cpp
......
......@@ -17,7 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "DiscoverMainWindow.h"
#include "DiscoverObject.h"
#include "PaginateModel.h"
#include "UnityLauncher.h"
#include "FeaturedModel.h"
......@@ -79,7 +79,7 @@ public:
}
};
DiscoverMainWindow::DiscoverMainWindow(CompactMode mode)
DiscoverObject::DiscoverObject(CompactMode mode)
: QObject()
, m_engine(new QQmlApplicationEngine)
, m_mode(mode)
......@@ -100,7 +100,7 @@ DiscoverMainWindow::DiscoverMainWindow(CompactMode mode)
qmlRegisterType<QQuickView>();
qmlRegisterType<QActionGroup>();
qmlRegisterType<QAction>();
qmlRegisterUncreatableType<DiscoverMainWindow>("org.kde.discover.app", 1, 0, "DiscoverMainWindow", QStringLiteral("don't do that"));
qmlRegisterUncreatableType<DiscoverObject>("org.kde.discover.app", 1, 0, "DiscoverMainWindow", QStringLiteral("don't do that"));
setupActions();
auto uri = "org.kde.discover";
......@@ -114,21 +114,21 @@ DiscoverMainWindow::DiscoverMainWindow(CompactMode mode)
m_engine->setNetworkAccessManagerFactory(m_networkAccessManagerFactory.data());
m_engine->rootContext()->setContextProperty(QStringLiteral("app"), this);
connect(m_engine, &QQmlApplicationEngine::objectCreated, this, &DiscoverMainWindow::integrateObject);
connect(m_engine, &QQmlApplicationEngine::objectCreated, this, &DiscoverObject::integrateObject);
m_engine->load(QUrl(QStringLiteral("qrc:/qml/DiscoverWindow.qml")));
}
DiscoverMainWindow::~DiscoverMainWindow()
DiscoverObject::~DiscoverObject()
{
delete m_engine;
}
bool DiscoverMainWindow::isRoot()
bool DiscoverObject::isRoot()
{
return ::getuid() == 0;
}
QStringList DiscoverMainWindow::modes() const
QStringList DiscoverObject::modes() const
{
QStringList ret;
QObject* obj = rootObject();
......@@ -142,7 +142,7 @@ QStringList DiscoverMainWindow::modes() const
return ret;
}
void DiscoverMainWindow::openMode(const QString& _mode)
void DiscoverObject::openMode(const QString& _mode)
{
if(!modes().contains(_mode))
qWarning() << "unknown mode" << _mode;
......@@ -159,12 +159,12 @@ void DiscoverMainWindow::openMode(const QString& _mode)
obj->setProperty("currentTopLevel", modeComp);
}
void DiscoverMainWindow::openMimeType(const QString& mime)
void DiscoverObject::openMimeType(const QString& mime)
{
emit listMimeInternal(mime);
}
void DiscoverMainWindow::openCategory(const QString& category)
void DiscoverObject::openCategory(const QString& category)
{
rootObject()->setProperty("defaultStartup", false);
auto action = new OneTimeAction(
......@@ -186,7 +186,7 @@ void DiscoverMainWindow::openCategory(const QString& category)
}
}
void DiscoverMainWindow::openLocalPackage(const QUrl& localfile)
void DiscoverObject::openLocalPackage(const QUrl& localfile)
{
if (!QFile::exists(localfile.toLocalFile())) {
// showPassiveNotification(i18n("Trying to open unexisting file '%1'", localfile.toString()));
......@@ -214,13 +214,13 @@ void DiscoverMainWindow::openLocalPackage(const QUrl& localfile)
}
}
void DiscoverMainWindow::openApplication(const QUrl& url)
void DiscoverObject::openApplication(const QUrl& url)
{
Q_ASSERT(!url.isEmpty());
Q_EMIT openUrl(url);
}
void DiscoverMainWindow::integrateObject(QObject* object)
void DiscoverObject::integrateObject(QObject* object)
{
if (!object) {
qWarning() << "Errors when loading the GUI";
......@@ -244,7 +244,7 @@ void DiscoverMainWindow::integrateObject(QObject* object)
connect(object, &QObject::destroyed, qGuiApp, &QCoreApplication::quit);
}
bool DiscoverMainWindow::eventFilter(QObject * object, QEvent * event)
bool DiscoverObject::eventFilter(QObject * object, QEvent * event)
{
if (object!=rootObject())
return false;
......@@ -265,40 +265,40 @@ bool DiscoverMainWindow::eventFilter(QObject * object, QEvent * event)
return false;
}
void DiscoverMainWindow::setupActions()
void DiscoverObject::setupActions()
{
if (KAuthorized::authorizeAction(QStringLiteral("help_contents"))) {
auto mHandBookAction = KStandardAction::helpContents(this, &DiscoverMainWindow::appHelpActivated, this);
auto mHandBookAction = KStandardAction::helpContents(this, &DiscoverObject::appHelpActivated, this);
m_collection[mHandBookAction->objectName()] = mHandBookAction;
}
if (KAuthorized::authorizeAction(QStringLiteral("help_report_bug")) && !KAboutData::applicationData().bugAddress().isEmpty()) {
auto mReportBugAction = KStandardAction::reportBug(this, &DiscoverMainWindow::reportBug, this);
auto mReportBugAction = KStandardAction::reportBug(this, &DiscoverObject::reportBug, this);
m_collection[mReportBugAction->objectName()] = mReportBugAction;
}
if (KAuthorized::authorizeAction(QStringLiteral("help_about_app"))) {
auto mAboutAppAction = KStandardAction::aboutApp(this, &DiscoverMainWindow::aboutApplication, this);
auto mAboutAppAction = KStandardAction::aboutApp(this, &DiscoverObject::aboutApplication, this);
m_collection[mAboutAppAction->objectName()] = mAboutAppAction;
}
}
QAction * DiscoverMainWindow::action(const QString& name) const
QAction * DiscoverObject::action(const QString& name) const
{
return m_collection.value(name);
}
QString DiscoverMainWindow::iconName(const QIcon& icon)
QString DiscoverObject::iconName(const QIcon& icon)
{
return icon.name();
}
void DiscoverMainWindow::appHelpActivated()
void DiscoverObject::appHelpActivated()
{
QDesktopServices::openUrl(QUrl(QStringLiteral("help:/")));
}
void DiscoverMainWindow::aboutApplication()
void DiscoverObject::aboutApplication()
{
static QPointer<QDialog> dialog;
if (!dialog) {
......@@ -308,7 +308,7 @@ void DiscoverMainWindow::aboutApplication()
dialog->show();
}
void DiscoverMainWindow::reportBug()
void DiscoverObject::reportBug()
{
static QPointer<QDialog> dialog;
if (!dialog) {
......@@ -318,14 +318,14 @@ void DiscoverMainWindow::reportBug()
dialog->show();
}
void DiscoverMainWindow::switchApplicationLanguage()
void DiscoverObject::switchApplicationLanguage()
{
// auto langDialog = new KSwitchLanguageDialog(nullptr);
// connect(langDialog, SIGNAL(finished(int)), this, SLOT(dialogFinished()));
// langDialog->show();
}
void DiscoverMainWindow::setCompactMode(DiscoverMainWindow::CompactMode mode)
void DiscoverObject::setCompactMode(DiscoverObject::CompactMode mode)
{
if (m_mode != mode) {
m_mode = mode;
......@@ -381,21 +381,21 @@ private:
QList<QQmlError> m_warnings;
};
void DiscoverMainWindow::loadTest(const QUrl& url)
void DiscoverObject::loadTest(const QUrl& url)
{
new DiscoverTestExecutor(rootObject(), engine(), url);
}
QWindow* DiscoverMainWindow::rootObject() const
QWindow* DiscoverObject::rootObject() const
{
return qobject_cast<QWindow*>(m_engine->rootObjects().at(0));
}
void DiscoverMainWindow::showPassiveNotification(const QString& msg)
void DiscoverObject::showPassiveNotification(const QString& msg)
{
QTimer::singleShot(100, this, [this, msg](){
QMetaObject::invokeMethod(rootObject(), "showPassiveNotification", Qt::QueuedConnection, Q_ARG(QVariant, msg), Q_ARG(QVariant, {}), Q_ARG(QVariant, {}), Q_ARG(QVariant, {}));
});
}
#include "DiscoverMainWindow.moc"
#include "DiscoverObject.moc"
......@@ -31,7 +31,7 @@ class QQmlApplicationEngine;
class CachedNetworkAccessManagerFactory;
class ResourcesProxyModel;
class DiscoverMainWindow : public QObject
class DiscoverObject : public QObject
{
Q_OBJECT
Q_PROPERTY(CompactMode compactMode READ compactMode WRITE setCompactMode NOTIFY compactModeChanged)
......@@ -40,8 +40,8 @@ class DiscoverMainWindow : public QObject
enum CompactMode { Auto, Compact, Full };
Q_ENUM(CompactMode)
explicit DiscoverMainWindow(CompactMode mode);
~DiscoverMainWindow() override;
explicit DiscoverObject(CompactMode mode);
~DiscoverObject() override;
QStringList modes() const;
void setupActions();
......
......@@ -26,17 +26,17 @@
#include <KLocalizedString>
#include <QCommandLineParser>
#include <qwindow.h>
#include "DiscoverMainWindow.h"
#include "DiscoverObject.h"
#include <DiscoverBackendsFactory.h>
#include "DiscoverVersion.h"
#include <QTextStream>
#include <QStandardPaths>
typedef QHash<QString, DiscoverMainWindow::CompactMode> StringCompactMode;
typedef QHash<QString, DiscoverObject::CompactMode> StringCompactMode;
Q_GLOBAL_STATIC_WITH_ARGS(StringCompactMode, s_decodeCompactMode, (StringCompactMode {
{ QLatin1String("auto"), DiscoverMainWindow::Auto },
{ QLatin1String("compact"), DiscoverMainWindow::Compact },
{ QLatin1String("full"), DiscoverMainWindow::Full }
{ QLatin1String("auto"), DiscoverObject::Auto },
{ QLatin1String("compact"), DiscoverObject::Compact },
{ QLatin1String("full"), DiscoverObject::Full }
}))
QCommandLineParser* createParser()
......@@ -59,7 +59,7 @@ QCommandLineParser* createParser()
return parser;
}
void processArgs(QCommandLineParser* parser, DiscoverMainWindow* mainWindow)
void processArgs(QCommandLineParser* parser, DiscoverObject* mainWindow)
{
if(parser->isSet(QStringLiteral("application")))
mainWindow->openApplication(QUrl(parser->value(QStringLiteral("application"))));
......@@ -100,7 +100,7 @@ int main(int argc, char** argv)
about.setProductName("discover/discover");
KAboutData::setApplicationData(about);
DiscoverMainWindow *mainWindow = nullptr;
DiscoverObject *mainWindow = nullptr;
{
QScopedPointer<QCommandLineParser> parser(createParser());
parser->process(app);
......@@ -121,8 +121,8 @@ int main(int argc, char** argv)
KDBusService* service = new KDBusService(KDBusService::Unique, &app);
mainWindow = new DiscoverMainWindow(s_decodeCompactMode->value(parser->value(QStringLiteral("compact")), DiscoverMainWindow::Full));
QObject::connect(&app, &QCoreApplication::aboutToQuit, mainWindow, &DiscoverMainWindow::deleteLater);
mainWindow = new DiscoverObject(s_decodeCompactMode->value(parser->value(QStringLiteral("compact")), DiscoverObject::Full));
QObject::connect(&app, &QCoreApplication::aboutToQuit, mainWindow, &DiscoverObject::deleteLater);
QObject::connect(service, &KDBusService::activateRequested, mainWindow, [mainWindow](const QStringList &arguments, const QString &/*workingDirectory*/){
if (!mainWindow->rootObject())
QCoreApplication::instance()->quit();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment