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-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
|
|
|
|
{
|
|
|
|
int h = 64; // height 64 + 4px margin top and down
|
|
|
|
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();
|
|
|
|
|
|
|
|
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-10-13 18:41:24 +04:00
|
|
|
subFont.setWeight(subFont.weight()-2);
|
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-10-12 18:58:54 +04:00
|
|
|
|
|
|
|
QSize iconsize = icon.actualSize(option.decorationSize);
|
|
|
|
|
|
|
|
QRect headerRect = option.rect;
|
|
|
|
QRect subheaderRect = option.rect;
|
|
|
|
QRect iconRect = subheaderRect;
|
|
|
|
|
|
|
|
iconRect.setRight(iconsize.width()+30);
|
|
|
|
iconRect.setTop(iconRect.top()+5);
|
|
|
|
headerRect.setLeft(iconRect.right());
|
|
|
|
subheaderRect.setLeft(iconRect.right());
|
|
|
|
headerRect.setTop(headerRect.top()+5);
|
|
|
|
headerRect.setBottom(headerRect.top()+fm.height());
|
|
|
|
|
2011-10-13 18:41:24 +04:00
|
|
|
subheaderRect.setTop(headerRect.bottom());
|
|
|
|
QFontMetrics fmSub( subFont );
|
|
|
|
subheaderRect.setBottom(subheaderRect.top()+fmSub.height());
|
|
|
|
QRect statusRect = subheaderRect;
|
|
|
|
statusRect.setTop( subheaderRect.bottom() + 2 );
|
|
|
|
statusRect.setBottom( statusRect.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()));
|
|
|
|
painter->drawPixmap(QPoint(iconRect.left()+iconsize.width()/2+2,iconRect.top()+iconsize.height()/2+3),icon.pixmap(iconsize.width(),iconsize.height()));
|
|
|
|
|
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-10-13 18:41:24 +04:00
|
|
|
painter->drawText(statusRect, tr("Status: %1").arg( statusText ));
|
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 );
|
|
|
|
|
|
|
|
_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 );
|
|
|
|
|
|
|
|
connect(_ButtonClose, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
connect(_ButtonRemove, SIGNAL(clicked()), this, SLOT(slotRemoveFolder()));
|
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();
|
|
|
|
item->setData( QIcon::fromTheme( "folder-sync" ), FolderViewDelegate::FolderIconRole );
|
|
|
|
item->setData( f->path(), FolderViewDelegate::FolderPathRole );
|
|
|
|
item->setData( f->alias(), FolderViewDelegate::FolderNameRole );
|
2011-10-13 18:41:24 +04:00
|
|
|
|
|
|
|
SyncResult res = f->lastSyncResult();
|
|
|
|
QString resultStr = tr("Undefined");
|
|
|
|
QString statusIcon = "view-refresh";
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
item->setData( QIcon::fromTheme( statusIcon ), FolderViewDelegate::FolderStatusIcon );
|
|
|
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "statusdialog.moc"
|