Commit 13fcf5ad authored by Jarek Kobus's avatar Jarek Kobus

Refactor UpdateInfo plugin

Change-Id: I63fc40b12e29204d9ecd4ed3fd33e7ad3171918d
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 41ea6924
......@@ -182,6 +182,7 @@ const char G_WINDOW_OTHER[] = "QtCreator.Group.Window.Other";
const char G_HELP_HELP[] = "QtCreator.Group.Help.Help";
const char G_HELP_SUPPORT[] = "QtCreator.Group.Help.Supprt";
const char G_HELP_ABOUT[] = "QtCreator.Group.Help.About";
const char G_HELP_UPDATES[] = "QtCreator.Group.Help.Updates";
const char ICON_MINUS[] = ":/core/images/minus.png";
const char ICON_PLUS[] = ":/core/images/plus.png";
......
......@@ -453,6 +453,7 @@ void MainWindow::registerDefaultContainers()
ac->appendGroup(Constants::G_HELP_HELP);
ac->appendGroup(Constants::G_HELP_SUPPORT);
ac->appendGroup(Constants::G_HELP_ABOUT);
ac->appendGroup(Constants::G_HELP_UPDATES);
}
void MainWindow::registerDefaultActions()
......
......@@ -52,6 +52,7 @@ SUBDIRS = \
qmakeandroidsupport \
winrt \
qmlprofiler \
updateinfo \
welcome
DO_NOT_BUILD_QMLDESIGNER = $$(DO_NOT_BUILD_QMLDESIGNER)
......
......@@ -29,21 +29,31 @@
****************************************************************************/
#include "settingspage.h"
#include "updateinfoplugin.h"
#include <coreplugin/coreconstants.h>
#include <utils/qtcassert.h>
#include <utils/progressindicator.h>
#include <QDate>
using namespace UpdateInfo;
using namespace UpdateInfo::Internal;
namespace {
static const char FILTER_OPTIONS_PAGE_ID[] = "Update";
static const char FILTER_OPTIONS_PAGE[] = QT_TRANSLATE_NOOP("Update", "Update");
}
SettingsPage::SettingsPage(UpdateInfoPlugin *plugin)
: m_widget(0)
, m_plugin(plugin)
{
setId(Constants::FILTER_OPTIONS_PAGE);
setId(FILTER_OPTIONS_PAGE_ID);
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON));
setDisplayName(QCoreApplication::translate("Update", UpdateInfo::Constants::FILTER_OPTIONS_PAGE));
setDisplayName(QCoreApplication::translate("Update", FILTER_OPTIONS_PAGE));
setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE));
}
......@@ -52,17 +62,116 @@ QWidget *SettingsPage::widget()
if (!m_widget) {
m_widget = new QWidget;
m_ui.setupUi(m_widget);
m_ui.m_timeTable->setItemText(m_ui.m_timeTable->currentIndex(), QTime(m_plugin->scheduledUpdateTime())
.toString(QLatin1String("hh:mm")));
m_ui.m_checkIntervalComboBox->addItem(tr("Daily"), UpdateInfoPlugin::DailyCheck);
m_ui.m_checkIntervalComboBox->addItem(tr("Weekly"), UpdateInfoPlugin::WeeklyCheck);
m_ui.m_checkIntervalComboBox->addItem(tr("Monthly"), UpdateInfoPlugin::MonthlyCheck);
UpdateInfoPlugin::CheckUpdateInterval interval = m_plugin->checkUpdateInterval();
for (int i = 0; i < m_ui.m_checkIntervalComboBox->count(); i++) {
if (m_ui.m_checkIntervalComboBox->itemData(i).toInt() == interval) {
m_ui.m_checkIntervalComboBox->setCurrentIndex(i);
break;
}
}
m_ui.m_updatesGroupBox->setChecked(m_plugin->isAutomaticCheck());
updateLastCheckDate();
checkRunningChanged(m_plugin->isCheckForUpdatesRunning());
connect(m_ui.m_checkNowButton, &QPushButton::clicked,
m_plugin, &UpdateInfoPlugin::startCheckForUpdates);
connect(m_ui.m_checkIntervalComboBox,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SettingsPage::updateNextCheckDate);
connect(m_plugin, &UpdateInfoPlugin::lastCheckDateChanged,
this, &SettingsPage::updateLastCheckDate);
connect(m_plugin, &UpdateInfoPlugin::checkForUpdatesRunningChanged,
this, &SettingsPage::checkRunningChanged);
connect(m_plugin, &UpdateInfoPlugin::newUpdatesAvailable,
this, &SettingsPage::newUpdatesAvailable);
}
return m_widget;
}
UpdateInfoPlugin::CheckUpdateInterval SettingsPage::currentCheckInterval() const
{
QTC_ASSERT(m_widget, return UpdateInfoPlugin::WeeklyCheck);
return static_cast<UpdateInfoPlugin::CheckUpdateInterval>
(m_ui.m_checkIntervalComboBox->itemData(m_ui.m_checkIntervalComboBox->currentIndex()).toInt());
}
void SettingsPage::newUpdatesAvailable(bool available)
{
if (!m_widget)
return;
const QString message = available
? tr("New updates are available.")
: tr("No new updates are available.");
m_ui.m_messageLabel->setText(message);
}
void SettingsPage::checkRunningChanged(bool running)
{
if (!m_widget)
return;
m_ui.m_checkNowButton->setDisabled(running);
if (running) {
if (!m_progressIndicator) {
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Large);
m_progressIndicator->attachToWidget(m_widget);
}
m_progressIndicator->show();
} else {
if (m_progressIndicator) {
delete m_progressIndicator;
}
}
const QString message = running
? tr("Checking for updates...") : QString();
m_ui.m_messageLabel->setText(message);
}
void SettingsPage::updateLastCheckDate()
{
if (!m_widget)
return;
const QDate date = m_plugin->lastCheckDate();
QString lastCheckDateString;
if (date.isValid())
lastCheckDateString = date.toString();
else
lastCheckDateString = tr("Not checked yet");
m_ui.m_lastCheckDateLabel->setText(lastCheckDateString);
updateNextCheckDate();
}
void SettingsPage::updateNextCheckDate()
{
if (!m_widget)
return;
QDate date = m_plugin->nextCheckDate(currentCheckInterval());
if (!date.isValid() || date < QDate::currentDate())
date = QDate::currentDate();
m_ui.m_nextCheckDateLabel->setText(date.toString());
}
void SettingsPage::apply()
{
m_plugin->setScheduledUpdateTime(QTime::fromString(m_ui.m_timeTable->currentText(),
QLatin1String("hh:mm")));
m_plugin->saveSettings();
if (!m_widget)
return;
m_plugin->setCheckUpdateInterval(currentCheckInterval());
m_plugin->setAutomaticCheck(m_ui.m_updatesGroupBox->isChecked());
}
void SettingsPage::finish()
......
......@@ -32,11 +32,14 @@
#define SETTINGSPAGE_H
#include "ui_settingspage.h"
#include "updateinfoplugin.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <QPointer>
namespace Utils { class ProgressIndicator; }
namespace UpdateInfo {
namespace Internal {
......@@ -54,7 +57,14 @@ public:
void finish();
private:
void newUpdatesAvailable(bool available);
void checkRunningChanged(bool running);
void updateLastCheckDate();
void updateNextCheckDate();
UpdateInfoPlugin::CheckUpdateInterval currentCheckInterval() const;
QPointer<QWidget> m_widget;
QPointer<Utils::ProgressIndicator> m_progressIndicator;
Ui::SettingsWidget m_ui;
UpdateInfoPlugin *m_plugin;
};
......
......@@ -7,21 +7,34 @@
<x>0</x>
<y>0</y>
<width>482</width>
<height>364</height>
<height>242</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Filters</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="4">
<widget class="QGroupBox" name="m_updatesGroupBox">
<property name="title">
<string>Qt Creator Update Settings</string>
<string>Automatic Check for Updates</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="m_info">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Check interval basis:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="m_infoLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -29,196 +42,107 @@
</sizepolicy>
</property>
<property name="text">
<string>Qt Creator automatically runs a scheduled update check on a daily basis. If Qt Creator is not in use on the scheduled time or maintenance is behind schedule, the automatic update check will be run next time Qt Creator starts.</string>
<string>Qt Creator automatically runs a scheduled check for updates on a time interval basis. If Qt Creator is not in use on the scheduled date, the automatic check for updates will be performed next time Qt Creator starts.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="1" column="1">
<widget class="QComboBox" name="m_checkIntervalComboBox">
<property name="currentIndex">
<number>-1</number>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<width>171</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Run update check daily at:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_timeTable">
<property name="currentIndex">
<number>12</number>
</property>
<item>
<property name="text">
<string notr="true">00:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">01:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">02:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">03:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">04:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">05:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">06:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">07:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">08:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">09:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">10:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">11:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">12:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">13:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">14:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">15:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">16:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">17:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">18:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">19:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">20:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">21:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">22:00</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">23:00</string>
</property>
</item>
</widget>
</item>
<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>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Next check date:</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>253</height>
</size>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="m_nextCheckDateLabel">
<property name="text">
<string/>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Last check date:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="m_lastCheckDateLabel">
<property name="text">
<string>Not checked yet</string>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>167</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="m_checkNowButton">
<property name="text">
<string>Check Now</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QLabel" name="m_messageLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>233</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
......
QT += network xml
HEADERS += updateinfoplugin.h \
updateinfobutton.h \
settingspage.h
SOURCES += updateinfoplugin.cpp \
updateinfobutton.cpp \
settingspage.cpp
FORMS += settingspage.ui
RESOURCES += updateinfo.qrc
......
......@@ -14,8 +14,6 @@ QtcPlugin {
pluginJsonReplacements: ({"UPDATEINFO_EXPERIMENTAL_STR": (enable ? "false": "true")})
files: [
"updateinfobutton.cpp",
"updateinfobutton.h",
"updateinfoplugin.cpp",
"updateinfoplugin.h",
"settingspage.cpp",
......
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "updateinfobutton.h"
#include <coreplugin/coreconstants.h>
#include <utils/stylehelper.h>
#include <QIcon>
#include <QPainter>
namespace UpdateInfo {
namespace Internal {
UpdateInfoButton::UpdateInfoButton(QWidget *parent) :
QAbstractButton(parent)
{
setIcon(QIcon(QLatin1String(":/updateinfo/images/update_available_logo.png")));
}
//copied from fancytoolbutton
QSize UpdateInfoButton::minimumSizeHint() const
{
return QSize(8, 8);
}
//copied from fancytoolbutton
QSize UpdateInfoButton::sizeHint() const
{
return iconSize().expandedTo(QSize(64, 38));
}
//copied from fancytoolbutton and removed unused things
void UpdateInfoButton::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
QRect iconRect(0, 0, Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
iconRect.moveCenter(rect().center());
Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled);
}
} //Internal
} //namespace UpdateInfo
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef UPDATEINFOBUTTON_H
#define UPDATEINFOBUTTON_H
#include <QAbstractButton>
namespace UpdateInfo {
namespace Internal {
class UpdateInfoButton : public QAbstractButton
{
Q_OBJECT
public:
explicit UpdateInfoButton(QWidget *parent = 0);
void paintEvent(QPaintEvent *event);
QSize sizeHint() const;
QSize minimumSizeHint() const;