SettingsDialog: Add new widet called ActivityWidget.

This is the new widget to display server activity.
This commit is contained in:
Klaas Freitag 2015-10-19 14:41:53 +02:00
parent 4ad165ce26
commit c66c259447
6 changed files with 290 additions and 10 deletions

View file

@ -21,6 +21,7 @@ set(client_UI
ignorelisteditor.ui
networksettings.ui
protocolwidget.ui
activitywidget.ui
synclogdialog.ui
settingsdialog.ui
sharedialog.ui
@ -55,6 +56,7 @@ set(client_SRCS
owncloudgui.cpp
owncloudsetupwizard.cpp
protocolwidget.cpp
activitywidget.cpp
selectivesyncdialog.cpp
settingsdialog.cpp
sharedialog.cpp

156
src/gui/activitywidget.cpp Normal file
View file

@ -0,0 +1,156 @@
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.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; version 2 of the License.
*
* 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.
*/
#include <QtGui>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets>
#endif
#include "activitywidget.h"
#include "configfile.h"
#include "syncresult.h"
#include "logger.h"
#include "utility.h"
#include "theme.h"
#include "folderman.h"
#include "syncfileitem.h"
#include "folder.h"
#include "openfilemanager.h"
#include "owncloudpropagator.h"
#include "ui_activitywidget.h"
#include <climits>
namespace OCC {
ActivityListModel::ActivityListModel(QWidget *parent)
:QAbstractListModel(parent)
{
}
QVariant ActivityListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::EditRole)
return QVariant();
switch (role) {
case Qt::ToolTipRole:
case Qt::DisplayRole:
return tr("%1 (%2)").arg("IM an item");
case Qt::DecorationRole:
return QFileIconProvider().icon(QFileIconProvider::Folder);
break;
}
return QVariant();
}
int ActivityListModel::rowCount(const QModelIndex&) const
{
return 4;
}
/* ==================================================================== */
ActivityWidget::ActivityWidget(QWidget *parent) :
QWidget(parent),
_ui(new Ui::ActivityWidget)
{
_ui->setupUi(this);
// Adjust copyToClipboard() when making changes here!
#if defined(Q_OS_MAC)
_ui->_activityList->setMinimumWidth(400);
#endif
_ui->_activityList->setModel(new ActivityListModel(this));
connect(this, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
_copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
_copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
_copyBtn->setEnabled(false);
connect(_copyBtn, SIGNAL(clicked()), SLOT(copyToClipboard()));
}
ActivityWidget::~ActivityWidget()
{
delete _ui;
}
void ActivityWidget::copyToClipboard()
{
QString text;
QTextStream ts(&text);
#if 0
int topLevelItems = _ui->_activityList->topLevelItemCount();
for (int i = 0; i < topLevelItems; i++) {
QTreeWidgetItem *child = _ui->_activityList->topLevelItem(i);
ts << left
// time stamp
<< qSetFieldWidth(10)
<< child->data(0,Qt::DisplayRole).toString()
// file name
<< qSetFieldWidth(64)
<< child->data(1,Qt::DisplayRole).toString()
// folder
<< qSetFieldWidth(30)
<< child->data(2, Qt::DisplayRole).toString()
// action
<< qSetFieldWidth(15)
<< child->data(3, Qt::DisplayRole).toString()
// size
<< qSetFieldWidth(10)
<< child->data(4, Qt::DisplayRole).toString()
<< qSetFieldWidth(0)
<< endl;
}
#endif
QApplication::clipboard()->setText(text);
emit guiLog(tr("Copied to clipboard"), tr("The sync status has been copied to the clipboard."));
}
// FIXME: Reused from protocol widget. Move over to utilities.
QString ActivityWidget::timeString(QDateTime dt, QLocale::FormatType format) const
{
const QLocale loc = QLocale::system();
QString dtFormat = loc.dateTimeFormat(format);
static const QRegExp re("(HH|H|hh|h):mm(?!:s)");
dtFormat.replace(re, "\\1:mm:ss");
return loc.toString(dt, dtFormat);
}
void ActivityWidget::slotOpenFile( )
{
// FIXME make work at all.
#if 0
QString folderName = item->data(2, Qt::UserRole).toString();
QString fileName = item->text(1);
Folder *folder = FolderMan::instance()->folder(folderName);
if (folder) {
// folder->path() always comes back with trailing path
QString fullPath = folder->path() + fileName;
if (QFile(fullPath).exists()) {
showInFileManager(fullPath);
}
}
#endif
}
}

82
src/gui/activitywidget.h Normal file
View file

@ -0,0 +1,82 @@
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.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; version 2 of the License.
*
* 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.
*/
#ifndef ACTIVITYWIDGET_H
#define ACTIVITYWIDGET_H
#include <QDialog>
#include <QDateTime>
#include <QLocale>
#include <QAbstractListModel>
#include "progressdispatcher.h"
#include "owncloudgui.h"
#include "ui_activitywidget.h"
class QPushButton;
namespace OCC {
namespace Ui {
class ActivityWidget;
}
class Application;
/**
* @brief The ActivityListModel
* @ingroup gui
*/
class ActivityListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit ActivityListModel(QWidget *parent=0);
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
};
/**
* @brief The ActivityWidget class
* @ingroup gui
*/
class ActivityWidget : public QWidget
{
Q_OBJECT
public:
explicit ActivityWidget(QWidget *parent = 0);
~ActivityWidget();
QSize sizeHint() const { return ownCloudGui::settingsDialogSize(); }
public slots:
void slotOpenFile();
protected slots:
void copyToClipboard();
protected:
signals:
void guiLog(const QString&, const QString&);
private:
QString timeString(QDateTime dt, QLocale::FormatType format) const;
Ui::ActivityWidget *_ui;
QPushButton *_copyBtn;
};
}
#endif // ActivityWIDGET_H

40
src/gui/activitywidget.ui Normal file
View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OCC::ActivityWidget</class>
<widget class="QWidget" name="OCC::ActivityWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>612</width>
<height>515</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Sync Activity</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QDialogButtonBox" name="_dialogButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QListView" name="_activityList"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -22,7 +22,7 @@
#include "configfile.h"
#include "progressdispatcher.h"
#include "owncloudgui.h"
#include "protocolwidget.h"
#include "activitywidget.h"
#include "accountmanager.h"
#include <QLabel>
@ -77,11 +77,11 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
// Note: all the actions have a '\n' because the account name is in two lines and
// all buttons must have the same size in order to keep a good layout
_protocolAction = createColorAwareAction(QLatin1String(":/client/resources/activity.png"), tr("Activity"));
_actionGroup->addAction(_protocolAction);
addActionToToolBar(_protocolAction);
ProtocolWidget *protocolWidget = new ProtocolWidget;
_ui->stack->addWidget(protocolWidget);
_activityAction = createColorAwareAction(QLatin1String(":/client/resources/activity.png"), tr("Activity"));
_actionGroup->addAction(_activityAction);
addActionToToolBar(_activityAction);
ActivityWidget *activityWidget = new ActivityWidget;
_ui->stack->addWidget(activityWidget);
QAction *generalAction = createColorAwareAction(QLatin1String(":/client/resources/settings.png"), tr("General"));
_actionGroup->addAction(generalAction);
@ -95,7 +95,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
NetworkSettings *networkSettings = new NetworkSettings;
_ui->stack->addWidget(networkSettings);
_actionGroupWidgets.insert(_protocolAction, protocolWidget);
_actionGroupWidgets.insert(_activityAction, activityWidget);
_actionGroupWidgets.insert(generalAction, generalSettings);
_actionGroupWidgets.insert(networkAction, networkSettings);
@ -178,8 +178,8 @@ void SettingsDialog::showFirstPage()
void SettingsDialog::showActivityPage()
{
if (_protocolAction) {
slotSwitchPage(_protocolAction);
if (_activityAction) {
slotSwitchPage(_activityAction);
}
}

View file

@ -79,7 +79,7 @@ private:
// Maps the actions from the action group to the toolbar actions
QHash<QAction*, QAction*> _toolbarAccountActions;
QAction * _protocolAction;
QAction * _activityAction;
ownCloudGui *_gui;
};