~ubuntu-branches/ubuntu/saucy/kget/saucy-updates

« back to all changes in this revision

Viewing changes to conf/transfersgroupwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:25:26 UTC
  • Revision ID: package-import@ubuntu.com-20130621022526-8ctjdwsa0twvsgks
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 
 
3
   Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
 
4
   Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
 
5
   Copyright (C) 2007 Javier Goday <jgoday @ gmail.com>
 
6
   Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
 
7
   Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
 
8
 
 
9
   This program is free software; you can redistribute it and/or
 
10
   modify it under the terms of the GNU General Public
 
11
   License as published by the Free Software Foundation; either
 
12
   version 2 of the License, or (at your option) any later version.
 
13
*/
 
14
 
 
15
#include "transfersgroupwidget.h"
 
16
#include "transfersgrouptree.h"
 
17
 
 
18
#include "core/kget.h"
 
19
#include "core/transfertreemodel.h"
 
20
#include "core/transfertreeselectionmodel.h"
 
21
 
 
22
 
 
23
TransfersGroupWidget::TransfersGroupWidget(QWidget *parent) 
 
24
    : QWidget(parent)
 
25
{
 
26
    ui.setupUi(this);
 
27
 
 
28
    ui.treeView->setModel(KGet::model());
 
29
    ui.treeView->setSelectionModel(KGet::selectionModel());
 
30
 
 
31
    ui.treeView->header()->hideSection(TransferTreeModel::Progress);
 
32
    ui.treeView->header()->hideSection(TransferTreeModel::RemainingTime);
 
33
    ui.treeView->header()->hideSection(TransferTreeModel::Size);
 
34
    ui.treeView->header()->hideSection(TransferTreeModel::Speed);
 
35
 
 
36
    ui.add->setGuiItem(KStandardGuiItem::add());
 
37
    ui.remove->setGuiItem(KStandardGuiItem::remove());
 
38
    ui.configure->setGuiItem(KStandardGuiItem::Configure);
 
39
    ui.rename->setIcon(KIcon("edit-rename"));
 
40
    ui.selectIcon->setIcon(KIcon("preferences-desktop-icons"));
 
41
 
 
42
    connect(ui.add, SIGNAL(clicked()), ui.treeView, SLOT(addGroup()));
 
43
    connect(ui.remove, SIGNAL(clicked()), ui.treeView, SLOT(deleteSelectedGroup()));
 
44
    connect(ui.rename, SIGNAL(clicked()), ui.treeView, SLOT(renameSelectedGroup()));
 
45
    connect(ui.selectIcon, SIGNAL(iconChanged(QString)), ui.treeView, SLOT(changeIcon(QString)));
 
46
    connect(ui.configure, SIGNAL(clicked()), KGet::actionCollection()->action("transfer_group_settings"), SLOT(trigger()));
 
47
    connect(ui.treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotSelectionChanged()));
 
48
 
 
49
    slotSelectionChanged();
 
50
}
 
51
 
 
52
void TransfersGroupWidget::slotSelectionChanged()
 
53
{
 
54
    const QModelIndexList selectedGroups = ui.treeView->selectionModel()->selectedRows();
 
55
    const bool somethingSelected = !selectedGroups.isEmpty();
 
56
    bool canDelete = somethingSelected;
 
57
 
 
58
    foreach (const QModelIndex &index, selectedGroups) {
 
59
        if (index.row() == 0) {
 
60
            canDelete = false;
 
61
            break;
 
62
        }
 
63
    }
 
64
 
 
65
    ui.rename->setEnabled(canDelete);
 
66
    ui.remove->setEnabled(canDelete);
 
67
    ui.configure->setEnabled(somethingSelected);
 
68
    ui.selectIcon->setEnabled(somethingSelected);
 
69
 
 
70
    if (somethingSelected && !KGet::selectedTransferGroups().isEmpty()) {
 
71
        ui.selectIcon->setIcon(KIcon(KGet::selectedTransferGroups().first()->iconName()));
 
72
    } else {
 
73
        ui.selectIcon->setIcon(KIcon("preferences-desktop-icons"));
 
74
    }
 
75
}