File: deletedialog.cpp

package info (click to toggle)
juk 4%3A18.08.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,820 kB
  • sloc: cpp: 17,240; xml: 617; makefile: 3; sh: 2
file content (143 lines) | stat: -rw-r--r-- 4,709 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 * Copyright (C) 2004, 2008 Michael Pyne <mpyne@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.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "deletedialog.h"
#include "ui_deletedialogbase.h"

#include <KStandardGuiItem>
#include <KLocalizedString>
#include <KIconLoader>
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>

#include <QDialogButtonBox>
#include <QStringList>
#include <QCheckBox>
#include <QVBoxLayout>

//////////////////////////////////////////////////////////////////////////////
// DeleteWidget implementation
//////////////////////////////////////////////////////////////////////////////

DeleteWidget::DeleteWidget(QWidget *parent)
    : QWidget(parent)
    , m_ui(new Ui::DeleteDialogBase)
{
    m_ui->setupUi(this);

    setObjectName(QLatin1String("delete_dialog_widget"));

    KConfigGroup messageGroup(KSharedConfig::openConfig(), "FileRemover");

    bool deleteInstead = messageGroup.readEntry("deleteInsteadOfTrash", false);
    slotShouldDelete(deleteInstead);
    m_ui->ddShouldDelete->setChecked(deleteInstead);

    // Forward on signals
    connect(m_ui->ddShouldDelete, SIGNAL(toggled(bool)), SIGNAL(signalShouldDelete(bool)));
    connect(m_ui->ddButtonBox,    SIGNAL(accepted()),    SIGNAL(accepted()));
    connect(m_ui->ddButtonBox,    SIGNAL(rejected()),    SIGNAL(rejected()));
}

void DeleteWidget::setFiles(const QStringList &files)
{
    m_ui->ddFileList->clear();
    m_ui->ddFileList->insertItems(0, files);
    m_ui->ddNumFiles->setText(i18np("<b>1</b> file selected.", "<b>%1</b> files selected.", files.count()));
}

bool DeleteWidget::shouldDelete() const
{
    return m_ui->ddShouldDelete->isChecked();
}

void DeleteWidget::slotShouldDelete(bool shouldDelete)
{
    if(shouldDelete) {
        m_ui->ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
            "deleted</b> from your hard disk.</qt>"));
        m_ui->ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("dialog-warning",
            KIconLoader::Desktop, KIconLoader::SizeLarge));
    }
    else {
        m_ui->ddDeleteText->setText(i18n("<qt>These items will be moved to the Trash Bin.</qt>"));
        m_ui->ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("user-trash-full",
            KIconLoader::Desktop, KIconLoader::SizeLarge));
    }
}

//////////////////////////////////////////////////////////////////////////////
// DeleteDialog implementation
//////////////////////////////////////////////////////////////////////////////

DeleteDialog::DeleteDialog(QWidget *parent) :
    QDialog(parent),
    m_trashGuiItem(i18n("&Send to Trash"), "user-trash-full")
{
    setObjectName(QLatin1String("juk_delete_dialog"));
    setModal(true);
    setWindowTitle(i18n("About to delete selected files"));

    auto layout = new QVBoxLayout(this);

    m_widget = new DeleteWidget(this);
    m_widget->setMinimumSize(400, 300);
    layout->addWidget(m_widget);

    // Trying to adjust for Qt bug with rich text where the layout is ignored
    // (something about not being able to get height-for-width on X11?)
    setMinimumSize(410, 326);
    adjustSize();

    slotShouldDelete(shouldDelete());

    connect(m_widget, SIGNAL(accepted()), SLOT(accept()));
    connect(m_widget, SIGNAL(rejected()), SLOT(reject()));
    connect(m_widget, SIGNAL(signalShouldDelete(bool)), SLOT(slotShouldDelete(bool)));
}

bool DeleteDialog::confirmDeleteList(const QStringList &condemnedFiles)
{
    m_widget->setFiles(condemnedFiles);

    return exec() == QDialog::Accepted;
}

void DeleteDialog::setFiles(const QStringList &files)
{
    m_widget->setFiles(files);
}

void DeleteDialog::accept()
{
    KConfigGroup messageGroup(KSharedConfig::openConfig(), "FileRemover");

    // Save user's preference

    messageGroup.writeEntry("deleteInsteadOfTrash", shouldDelete());
    messageGroup.sync();

    QDialog::accept();
}

void DeleteDialog::slotShouldDelete(bool shouldDelete)
{
    KGuiItem::assign(m_widget->m_ui->ddButtonBox->button(QDialogButtonBox::Ok),
                     shouldDelete ? KStandardGuiItem::del() : m_trashGuiItem);
}

// vim: set et sw=4 tw=0 sta: