Commit 752bc592 authored by Jiří Wolker's avatar Jiří Wolker Committed by Nate Graham
Browse files

Show a "Welcome screen" when launched without an archive

This merge request replaces the window contents when the Ark application
is started without giving it archive to open. The current user interface
has all its widgets (except the list view) in disabled state and the only
way to open or create archive is to use menu bar (not shown in pictures)
or keyboard shortcuts. It can be  hard to figure out what to do for
inexperienced users.

The new user interface adds two buttons directly to the center of window:
one for opening archive and the second for archive creation. When archive
is opened, this screen is replaced by the normal user interface.

This changes only Ark's main window, not Ark KPart, so it will not break
any existing usages of the KPart.
parent 7f67c1bc
......@@ -7,6 +7,7 @@ set(ark_SRCS
batchextract.cpp
main.cpp
mainwindow.cpp
welcomescreen.cpp
ark.qrc
)
......@@ -15,6 +16,10 @@ ecm_qt_declare_logging_category(ark_SRCS
IDENTIFIER ARK
CATEGORY_NAME ark.main DESCRIPTION "Ark Main" EXPORT ARK)
ki18n_wrap_ui(ark_SRCS
welcomescreen.ui)
# For Mac and Windows.
file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/icons/*-apps-ark.png")
......
......@@ -5,6 +5,7 @@
* Copyright (C) 2003: Helio Chissini de Castro <helio@conectiva.com>
* Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
* Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
* Copyright (C) 2021 Jiří Wolker <woljiri@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -30,6 +31,7 @@
#include "settingspage.h"
#include "pluginmanager.h"
#include "interface.h"
#include "welcomescreen.h"
#include <KParts/ReadWritePart>
#include <KPluginFactory>
......@@ -51,6 +53,7 @@
#include <QMimeData>
#include <QPointer>
#include <QStatusBar>
#include <QStackedWidget>
static bool isValidArchiveDrag(const QMimeData *data)
{
......@@ -59,11 +62,17 @@ static bool isValidArchiveDrag(const QMimeData *data)
MainWindow::MainWindow(QWidget *)
: KParts::MainWindow()
, m_welcomeScreen(new WelcomeScreen(this))
, m_windowContents(new QStackedWidget(this))
{
setupActions();
setAcceptDrops(true);
// Ark doesn't provide a fullscreen mode; remove the corresponding window button
setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint);
setCentralWidget(m_windowContents);
m_windowContents->addWidget(m_welcomeScreen);
showWelcomeScreen();
}
MainWindow::~MainWindow()
......@@ -71,6 +80,7 @@ MainWindow::~MainWindow()
guiFactory()->removeClient(m_part);
delete m_part;
m_part = nullptr;
m_welcomeScreen = nullptr;
}
void MainWindow::dragEnterEvent(QDragEnterEvent * event)
......@@ -136,7 +146,7 @@ bool MainWindow::loadPart()
}
m_part->setObjectName(QStringLiteral("ArkPart"));
setCentralWidget(m_part->widget());
m_windowContents->addWidget(m_part->widget());
setXMLFile(QStringLiteral("arkui.rc"));
setupGUI(ToolBar | Keys | Save);
......@@ -145,6 +155,7 @@ bool MainWindow::loadPart()
statusBar()->hide();
connect(m_part, SIGNAL(ready()), this, SLOT(updateActions()));
connect(m_part, SIGNAL(ready()), this, SLOT(hideWelcomeScreen()));
connect(m_part, SIGNAL(quit()), this, SLOT(quit()));
// #365200: this will disable m_recentFilesAction, while openUrl() will enable it.
// So updateActions() needs to be called after openUrl() returns.
......@@ -156,6 +167,17 @@ bool MainWindow::loadPart()
return true;
}
void MainWindow::showWelcomeScreen()
{
m_windowContents->setCurrentWidget(m_welcomeScreen);
}
void MainWindow::hideWelcomeScreen()
{
Q_ASSERT(m_part->widget());
m_windowContents->setCurrentWidget(m_part->widget());
}
void MainWindow::setupActions()
{
m_newAction = KStandardAction::openNew(this, &MainWindow::newArchive, this);
......@@ -169,6 +191,10 @@ void MainWindow::setupActions()
connect(m_recentFilesMenu, &KRecentFilesMenu::urlTriggered, this, &MainWindow::openUrl);
KStandardAction::preferences(this, &MainWindow::showSettings, actionCollection());
// Connect the welcome screen to actions created above
connect(m_welcomeScreen, &WelcomeScreen::newClicked, m_newAction, &QAction::trigger);
connect(m_welcomeScreen, &WelcomeScreen::openClicked, m_openAction, &QAction::trigger);
}
void MainWindow::updateActions()
......
......@@ -3,6 +3,7 @@
*
* Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
* Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
* Copyright (C) 2021 Jiří Wolker <woljiri@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -24,6 +25,9 @@
#include <KParts/MainWindow>
#include <KParts/OpenUrlArguments>
#include <QStackedWidget>
#include "welcomescreen.h"
namespace KParts
{
......@@ -48,6 +52,9 @@ public Q_SLOTS:
void openUrl(const QUrl &url);
void setShowExtractDialog(bool);
void showWelcomeScreen();
void hideWelcomeScreen();
protected:
void closeEvent(QCloseEvent *event) override;
QSize sizeHint() const override;
......@@ -69,6 +76,8 @@ private:
QAction *m_openAction;
QAction *m_newAction;
KParts::OpenUrlArguments m_openArgs;
WelcomeScreen *m_welcomeScreen;
QStackedWidget *m_windowContents;
};
#endif // MAINWINDOW_H
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2021 Jiří Wolker <woljiri@gmail.com>
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "welcomescreen.h"
WelcomeScreen::WelcomeScreen(QWidget *parent)
: QWidget(parent)
{
Q_ASSERT(parent);
setupUi(this);
appIcon->setPixmap(QIcon::fromTheme(QStringLiteral("utilities-file-archiver")).pixmap(128));
connect(openButton, &QPushButton::clicked, this, &WelcomeScreen::openClicked);
connect(newButton, &QPushButton::clicked, this, &WelcomeScreen::newClicked);
}
WelcomeScreen::~WelcomeScreen()
{
}
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2021 Jiří Wolker <woljiri@gmail.com>
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef WELCOMESCREEN_H
#define WELCOMESCREEN_H
#include "ui_welcomescreen.h"
#include <QFrame>
class WelcomeScreen: public QWidget, Ui::WelcomeScreen
{
Q_OBJECT
public:
explicit WelcomeScreen(QWidget *parent = nullptr);
~WelcomeScreen() override;
Q_SIGNALS:
void openClicked();
void newClicked();
};
#endif // WELCOMESCREEN_H
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2021 Jiří Wolker <woljiri@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
-->
<ui version="4.0">
<class>WelcomeScreen</class>
<widget class="QWidget" name="WelcomeScreen">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="appIcon">
<property name="text">
<string notr="true"/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Welcome to Ark</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>8</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="openButton">
<property name="text">
<string comment="to open an archive">Open Archive...</string>
</property>
<property name="icon">
<iconset theme="document-open"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newButton">
<property name="text">
<string>Create New Archive...</string>
</property>
<property name="icon">
<iconset theme="document-new"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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