deletedialog.cpp 4.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * 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/>.
 */
16

17
#include "deletedialog.h"
18
#include "ui_deletedialogbase.h"
19

20
#include <KApplication>
Aaron J. Seigo's avatar
build  
Aaron J. Seigo committed
21
#include <KStandardGuiItem>
22 23
#include <klocale.h>
#include <kiconloader.h>
24
#include <kconfig.h>
25
#include <kconfiggroup.h>
26
#include <kglobal.h>
27

28
#include <QStringList>
29
#include <QCheckBox>
30

31 32 33 34
//////////////////////////////////////////////////////////////////////////////
// DeleteWidget implementation
//////////////////////////////////////////////////////////////////////////////

35 36
DeleteWidget::DeleteWidget(QWidget *parent)
    : QWidget(parent), m_ui(new Ui::DeleteDialogBase)
37
{
38
    m_ui->setupUi(this);
39

Laurent Montel's avatar
Laurent Montel committed
40
    setObjectName( QLatin1String("delete_dialog_widget" ));
41

42
    KConfigGroup messageGroup(KGlobal::config()->group("FileRemover"));
43

44
    bool deleteInstead = messageGroup.readEntry("deleteInsteadOfTrash", false);
45
    slotShouldDelete(deleteInstead);
46 47 48 49
    m_ui->ddShouldDelete->setChecked(deleteInstead);

    // Forward on this signal.
    connect(m_ui->ddShouldDelete, SIGNAL(toggled(bool)), SIGNAL(signalShouldDelete(bool)));
50 51
}

52
void DeleteWidget::setFiles(const QStringList &files)
53
{
54
    m_ui->ddFileList->clear();
55
    m_ui->ddFileList->insertItems(0, files);
56 57 58 59 60 61
    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();
62 63
}

64 65 66
void DeleteWidget::slotShouldDelete(bool shouldDelete)
{
    if(shouldDelete) {
67
        m_ui->ddDeleteText->setText(i18n("<qt>These items will be <b>permanently "
68
            "deleted</b> from your hard disk.</qt>"));
69
        m_ui->ddWarningIcon->setPixmap(KIconLoader::global()->loadIcon("dialog-warning",
70
            KIconLoader::Desktop, KIconLoader::SizeLarge));
71 72
    }
    else {
73 74
        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",
75
            KIconLoader::Desktop, KIconLoader::SizeLarge));
76 77 78 79 80 81 82
    }
}

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

83
DeleteDialog::DeleteDialog(QWidget *parent) :
84
    KDialog(parent, Qt::MSWindowsFixedSizeDialogHint),
85
    m_trashGuiItem(i18n("&Send to Trash"), "user-trash-full")
86
{
Laurent Montel's avatar
Laurent Montel committed
87
    setObjectName( QLatin1String("delete_dialog" ));
Richard Lärkäng's avatar
Richard Lärkäng committed
88 89 90 91
    setModal(true);
    setCaption(i18n("About to delete selected files"));
    setButtons(Ok | Cancel);
    setDefaultButton(Cancel);
Laurent Montel's avatar
Laurent Montel committed
92
    showButtonSeparator(true);
Richard Lärkäng's avatar
Richard Lärkäng committed
93

94
    m_widget = new DeleteWidget(this);
95 96 97
    setMainWidget(m_widget);

    m_widget->setMinimumSize(400, 300);
98 99 100

    // 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?)
101 102 103 104 105
    setMinimumSize(410, 326);
    adjustSize();

    slotShouldDelete(shouldDelete());

106
    connect(m_widget, SIGNAL(signalShouldDelete(bool)), SLOT(slotShouldDelete(bool)));
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
}

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()
122
{
123
    KConfigGroup messageGroup(KGlobal::config()->group("FileRemover"));
124 125 126 127 128 129

    // Save user's preference

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

Richard Lärkäng's avatar
Richard Lärkäng committed
130
    KDialog::accept();
131 132
}

133 134
void DeleteDialog::slotShouldDelete(bool shouldDelete)
{
Aaron J. Seigo's avatar
build  
Aaron J. Seigo committed
135
    setButtonGuiItem(Ok, shouldDelete ? KStandardGuiItem::del() : m_trashGuiItem);
136 137 138 139
}

#include "deletedialog.moc"

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