2011-09-30 19:42:28 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
|
|
|
*
|
|
|
|
* 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.
|
2011-10-12 18:58:54 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtGui>
|
2011-09-26 23:46:26 +04:00
|
|
|
|
2011-09-26 15:12:00 +04:00
|
|
|
#include "statusdialog.h"
|
2011-09-26 23:46:26 +04:00
|
|
|
#include "folder.h"
|
2011-11-24 19:38:12 +04:00
|
|
|
#include "version.h"
|
2011-09-26 23:46:26 +04:00
|
|
|
|
2011-09-26 17:00:12 +04:00
|
|
|
namespace Mirall {
|
2011-10-12 18:58:54 +04:00
|
|
|
FolderViewDelegate::FolderViewDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderViewDelegate::~FolderViewDelegate()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated destructor stub
|
|
|
|
}
|
|
|
|
|
|
|
|
//alocate each item size in listview.
|
|
|
|
QSize FolderViewDelegate::sizeHint(const QStyleOptionViewItem & option ,
|
|
|
|
const QModelIndex & index) const
|
|
|
|
{
|
2011-12-26 00:55:29 +04:00
|
|
|
int h = 70; // height 64 + 4px margin top and down
|
2011-10-12 18:58:54 +04:00
|
|
|
int w = 0;
|
|
|
|
|
|
|
|
QString p = qvariant_cast<QString>(index.data(FolderPathRole));
|
|
|
|
QFont font = QApplication::font();
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
w = 8 + fm.boundingRect( p ).width();
|
|
|
|
|
|
|
|
return QSize( w, h );
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
QStyledItemDelegate::paint(painter,option,index);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
|
2011-10-20 12:26:40 +04:00
|
|
|
QFont font = QApplication::font();
|
2011-10-13 18:41:24 +04:00
|
|
|
QFont subFont = QApplication::font();
|
2011-10-12 18:58:54 +04:00
|
|
|
//font.setPixelSize(font.weight()+);
|
|
|
|
font.setBold(true);
|
2011-12-26 00:55:29 +04:00
|
|
|
subFont.setWeight(subFont.weight() - 4);
|
2011-10-12 18:58:54 +04:00
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
|
|
|
QIcon icon = qvariant_cast<QIcon>(index.data(FolderIconRole));
|
2011-10-13 18:41:24 +04:00
|
|
|
QIcon statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIcon));
|
2011-10-12 18:58:54 +04:00
|
|
|
QString aliasText = qvariant_cast<QString>(index.data(FolderNameRole));
|
|
|
|
QString pathText = qvariant_cast<QString>(index.data(FolderPathRole));
|
2011-10-13 18:41:24 +04:00
|
|
|
QString statusText = qvariant_cast<QString>(index.data(FolderStatus));
|
2011-12-26 00:55:29 +04:00
|
|
|
bool syncEnabled = index.data(FolderSyncEnabled).toBool();
|
|
|
|
QString syncStatus = syncEnabled? tr( "Enabled" ) : tr( "Disabled" );
|
2011-10-12 18:58:54 +04:00
|
|
|
|
2011-10-20 12:26:40 +04:00
|
|
|
QSize iconsize(48,48); // = icon.actualSize(option.decorationSize);
|
2011-10-12 18:58:54 +04:00
|
|
|
|
|
|
|
QRect headerRect = option.rect;
|
2011-12-26 00:55:29 +04:00
|
|
|
QRect iconRect = option.rect;
|
2011-10-12 18:58:54 +04:00
|
|
|
|
|
|
|
iconRect.setRight(iconsize.width()+30);
|
|
|
|
iconRect.setTop(iconRect.top()+5);
|
|
|
|
headerRect.setLeft(iconRect.right());
|
|
|
|
headerRect.setTop(headerRect.top()+5);
|
|
|
|
headerRect.setBottom(headerRect.top()+fm.height());
|
|
|
|
|
2011-12-26 00:55:29 +04:00
|
|
|
QRect subheaderRect = headerRect;
|
2011-10-13 18:41:24 +04:00
|
|
|
subheaderRect.setTop(headerRect.bottom());
|
|
|
|
QFontMetrics fmSub( subFont );
|
|
|
|
subheaderRect.setBottom(subheaderRect.top()+fmSub.height());
|
|
|
|
QRect statusRect = subheaderRect;
|
2011-12-26 00:55:29 +04:00
|
|
|
statusRect.setTop( subheaderRect.bottom() + 5);
|
2011-10-13 18:41:24 +04:00
|
|
|
statusRect.setBottom( statusRect.top() + fmSub.height());
|
2011-10-12 18:58:54 +04:00
|
|
|
|
2011-12-26 00:55:29 +04:00
|
|
|
QRect lastSyncRect = statusRect;
|
|
|
|
lastSyncRect.setTop( statusRect.bottom());
|
|
|
|
lastSyncRect.setBottom( lastSyncRect.top() + fmSub.height());
|
|
|
|
|
2011-10-12 18:58:54 +04:00
|
|
|
//painter->drawPixmap(QPoint(iconRect.right()/2,iconRect.top()/2),icon.pixmap(iconsize.width(),iconsize.height()));
|
2011-10-20 12:26:40 +04:00
|
|
|
painter->drawPixmap(QPoint(iconRect.left()+15,iconRect.top()),icon.pixmap(iconsize.width(),iconsize.height()));
|
2011-10-12 18:58:54 +04:00
|
|
|
|
2011-10-13 18:41:24 +04:00
|
|
|
painter->drawPixmap(QPoint(option.rect.right() - 4 - 48, option.rect.top() + 8 ), statusIcon.pixmap( 48,48));
|
|
|
|
|
|
|
|
|
2011-10-12 18:58:54 +04:00
|
|
|
painter->setFont(font);
|
|
|
|
painter->drawText(headerRect, aliasText);
|
|
|
|
|
2011-10-13 18:41:24 +04:00
|
|
|
painter->setFont(subFont);
|
2011-10-12 18:58:54 +04:00
|
|
|
painter->drawText(subheaderRect.left(),subheaderRect.top()+17, pathText);
|
2011-12-26 00:55:29 +04:00
|
|
|
painter->drawText(lastSyncRect, tr("Last Sync: %1").arg( statusText ));
|
|
|
|
painter->drawText(statusRect, tr("Sync Status: %1").arg( syncStatus ));
|
2011-10-12 18:58:54 +04:00
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ====================================================================================
|
2011-09-26 15:12:00 +04:00
|
|
|
|
|
|
|
StatusDialog::StatusDialog(QWidget *parent) :
|
|
|
|
QDialog(parent)
|
|
|
|
{
|
2011-10-12 18:58:54 +04:00
|
|
|
setupUi( this );
|
2011-11-24 19:38:12 +04:00
|
|
|
setWindowTitle( tr("Mirall %1").arg( VERSION_STRING ) );
|
2011-10-12 18:58:54 +04:00
|
|
|
|
|
|
|
_model = new QStandardItemModel();
|
|
|
|
FolderViewDelegate *delegate = new FolderViewDelegate();
|
2011-09-26 23:46:26 +04:00
|
|
|
|
2011-10-12 18:58:54 +04:00
|
|
|
_folderList->setItemDelegate( delegate );
|
|
|
|
_folderList->setModel( _model );
|
2011-10-20 12:26:40 +04:00
|
|
|
_folderList->setMinimumWidth( 300 );
|
2011-10-12 18:58:54 +04:00
|
|
|
|
2011-10-20 12:26:40 +04:00
|
|
|
connect(_ButtonClose, SIGNAL(clicked()), this, SLOT(accept()));
|
2011-10-12 18:58:54 +04:00
|
|
|
connect(_ButtonRemove, SIGNAL(clicked()), this, SLOT(slotRemoveFolder()));
|
2011-10-20 12:26:40 +04:00
|
|
|
connect(_ButtonFetch, SIGNAL(clicked()), this, SLOT(slotFetchFolder()));
|
2011-12-05 15:01:39 +04:00
|
|
|
connect(_ButtonPush, SIGNAL(clicked()), this, SLOT(slotPushFolder()));
|
2011-10-20 13:48:41 +04:00
|
|
|
connect(_ButtonOpenOC, SIGNAL(clicked()), this, SLOT(slotOpenOC()));
|
2011-12-12 20:47:30 +04:00
|
|
|
connect(_ButtonEnable, SIGNAL(clicked()), this, SLOT(slotEnableFolder()));
|
2011-10-20 12:26:40 +04:00
|
|
|
|
2011-10-20 13:48:41 +04:00
|
|
|
_ButtonOpenOC->setEnabled(false);
|
2011-10-20 12:26:40 +04:00
|
|
|
_ButtonRemove->setEnabled(false);
|
|
|
|
_ButtonFetch->setEnabled(false);
|
2011-12-05 15:01:39 +04:00
|
|
|
_ButtonPush->setEnabled(false);
|
2011-12-12 20:47:30 +04:00
|
|
|
_ButtonEnable->setEnabled(false);
|
2011-10-20 12:26:40 +04:00
|
|
|
|
|
|
|
connect(_folderList, SIGNAL(activated(QModelIndex)), SLOT(slotFolderActivated(QModelIndex)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatusDialog::slotFolderActivated( const QModelIndex& indx )
|
|
|
|
{
|
|
|
|
bool state = indx.isValid();
|
|
|
|
|
|
|
|
_ButtonRemove->setEnabled( state );
|
|
|
|
_ButtonFetch->setEnabled( state );
|
2011-12-05 15:01:39 +04:00
|
|
|
_ButtonPush->setEnabled( state );
|
2011-12-12 20:47:30 +04:00
|
|
|
_ButtonEnable->setEnabled( state );
|
|
|
|
|
|
|
|
if ( state ) {
|
|
|
|
bool folderEnabled = _model->data( indx, FolderViewDelegate::FolderSyncEnabled).toBool();
|
|
|
|
qDebug() << "folder is sync enabled: " << folderEnabled;
|
|
|
|
if ( folderEnabled ) {
|
|
|
|
_ButtonEnable->setText( tr( "disable" ) );
|
|
|
|
} else {
|
|
|
|
_ButtonEnable->setText( tr( "enable" ) );
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 23:46:26 +04:00
|
|
|
}
|
|
|
|
|
2011-10-12 18:58:54 +04:00
|
|
|
void StatusDialog::setFolderList( Folder::Map folders )
|
2011-09-26 23:46:26 +04:00
|
|
|
{
|
2011-10-12 18:58:54 +04:00
|
|
|
_model->clear();
|
|
|
|
|
|
|
|
foreach( Folder *f, folders ) {
|
|
|
|
qDebug() << "Folder: " << f;
|
|
|
|
QStandardItem *item = new QStandardItem();
|
2011-10-20 12:26:40 +04:00
|
|
|
QIcon icon = f->icon( 48 );
|
|
|
|
item->setData( icon, FolderViewDelegate::FolderIconRole );
|
2011-10-12 18:58:54 +04:00
|
|
|
item->setData( f->path(), FolderViewDelegate::FolderPathRole );
|
|
|
|
item->setData( f->alias(), FolderViewDelegate::FolderNameRole );
|
2011-12-12 20:47:30 +04:00
|
|
|
item->setData( f->syncEnabled(), FolderViewDelegate::FolderSyncEnabled );
|
|
|
|
qDebug() << "Folder is SyncEnabled: " << f->syncEnabled();
|
2011-10-13 18:41:24 +04:00
|
|
|
|
|
|
|
SyncResult res = f->lastSyncResult();
|
|
|
|
QString resultStr = tr("Undefined");
|
|
|
|
QString statusIcon = "view-refresh";
|
2011-11-04 14:41:49 +04:00
|
|
|
qDebug() << "Status: " << res.result();
|
2011-10-13 18:41:24 +04:00
|
|
|
if( res.result() == SyncResult::Error ) {
|
|
|
|
resultStr = tr("Error");
|
|
|
|
statusIcon = "dialog-close";
|
|
|
|
} else if( res.result() == SyncResult::Success ) {
|
|
|
|
resultStr = tr("Success");
|
|
|
|
statusIcon = "dialog-ok";
|
|
|
|
} else if( res.result() == SyncResult::Disabled ) {
|
|
|
|
resultStr = tr("Disabled");
|
|
|
|
statusIcon = "dialog-cancel";
|
2011-11-04 14:41:49 +04:00
|
|
|
} else if( res.result() == SyncResult::SetupError ) {
|
|
|
|
resultStr = tr( "Setup Error" );
|
|
|
|
statusIcon = "dialog-cancel";
|
2011-10-13 18:41:24 +04:00
|
|
|
}
|
2011-11-28 17:53:34 +04:00
|
|
|
item->setData( QIcon::fromTheme( statusIcon, QIcon( QString( ":/mirall/resources/%1").arg(statusIcon))), FolderViewDelegate::FolderStatusIcon );
|
2011-10-13 18:41:24 +04:00
|
|
|
item->setData( resultStr, FolderViewDelegate::FolderStatus );
|
|
|
|
item->setData( res.errorString(), FolderViewDelegate::FolderErrorMsg );
|
|
|
|
|
2011-10-12 18:58:54 +04:00
|
|
|
_model->appendRow( item );
|
|
|
|
}
|
2011-09-26 23:46:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatusDialog::slotRemoveFolder()
|
|
|
|
{
|
2011-10-13 15:55:52 +04:00
|
|
|
QModelIndex selected = _folderList->selectionModel()->currentIndex();
|
|
|
|
if( selected.isValid() ) {
|
|
|
|
QString alias = _model->data( selected, FolderViewDelegate::FolderNameRole ).toString();
|
|
|
|
qDebug() << "Remove Folder alias " << alias;
|
|
|
|
if( !alias.isEmpty() ) {
|
|
|
|
emit(removeFolderAlias( alias ));
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 15:12:00 +04:00
|
|
|
}
|
2011-09-26 17:00:12 +04:00
|
|
|
|
2011-10-18 12:22:24 +04:00
|
|
|
void StatusDialog::slotFetchFolder()
|
|
|
|
{
|
|
|
|
QModelIndex selected = _folderList->selectionModel()->currentIndex();
|
|
|
|
if( selected.isValid() ) {
|
|
|
|
QString alias = _model->data( selected, FolderViewDelegate::FolderNameRole ).toString();
|
|
|
|
qDebug() << "Fetch Folder alias " << alias;
|
|
|
|
if( !alias.isEmpty() ) {
|
|
|
|
emit(fetchFolderAlias( alias ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:01:39 +04:00
|
|
|
void StatusDialog::slotPushFolder()
|
|
|
|
{
|
|
|
|
QModelIndex selected = _folderList->selectionModel()->currentIndex();
|
|
|
|
if( selected.isValid() ) {
|
|
|
|
QString alias = _model->data( selected, FolderViewDelegate::FolderNameRole ).toString();
|
|
|
|
qDebug() << "Push Folder alias " << alias;
|
|
|
|
if( !alias.isEmpty() ) {
|
|
|
|
emit(pushFolderAlias( alias ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 20:47:30 +04:00
|
|
|
void StatusDialog::slotEnableFolder()
|
|
|
|
{
|
|
|
|
QModelIndex selected = _folderList->selectionModel()->currentIndex();
|
|
|
|
if( selected.isValid() ) {
|
|
|
|
QString alias = _model->data( selected, FolderViewDelegate::FolderNameRole ).toString();
|
|
|
|
bool folderEnabled = _model->data( selected, FolderViewDelegate::FolderSyncEnabled).toBool();
|
|
|
|
qDebug() << "Toggle enabled/disabled Folder alias " << alias << " - current state: " << folderEnabled;
|
|
|
|
if( !alias.isEmpty() ) {
|
|
|
|
emit(enableFolderAlias( alias, !folderEnabled ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-20 13:48:41 +04:00
|
|
|
void StatusDialog::setOCUrl( const QUrl& url )
|
|
|
|
{
|
|
|
|
_OCUrl = url;
|
|
|
|
if( url.isValid() )
|
|
|
|
_ButtonOpenOC->setEnabled( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatusDialog::slotOpenOC()
|
|
|
|
{
|
|
|
|
if( _OCUrl.isValid() )
|
|
|
|
QDesktopServices::openUrl( _OCUrl );
|
|
|
|
}
|
|
|
|
|
2011-09-26 17:00:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "statusdialog.moc"
|