~ubuntu-branches/ubuntu/hardy/kdebase-workspace/hardy

« back to all changes in this revision

Viewing changes to plasma/containments/desktop/backgrounddialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-03-03 11:37:30 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080303113730-ppdchskh93rr77le
Tags: 4:4.0.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <KColorButton>
30
30
#include <KDebug>
31
31
#include <KDirSelectDialog>
 
32
#include <KDirWatch>
32
33
#include <KFileDialog>
33
34
#include <KGlobalSettings>
34
35
#include <KLocalizedString>
117
118
    void reload(const QStringList &selected);
118
119
    void addBackground(const QString &path);
119
120
    int indexOf(const QString &path) const;
 
121
    void removeBackground(const QString &path);
120
122
    virtual bool contains(const QString &bg) const;
121
123
private:
122
124
    QObject *m_listener;
123
125
    QList<Background*> m_packages;
124
126
    float m_ratio;
 
127
    KDirWatch m_dirwatch;
125
128
};
126
129
 
127
130
class BackgroundDelegate : public QAbstractItemDelegate
150
153
: m_listener(listener)
151
154
, m_ratio(ratio)
152
155
{
 
156
    connect(&m_dirwatch, SIGNAL(deleted(QString)), listener, SLOT(removeBackground(QString)));
 
157
}
 
158
 
 
159
void BackgroundListModel::removeBackground(const QString &path)
 
160
{
 
161
    int index;
 
162
    while ((index = indexOf(path)) != -1) {
 
163
        beginRemoveRows(QModelIndex(), index, index);
 
164
        m_packages.removeAt(index);
 
165
        endRemoveRows();
 
166
    }
153
167
}
154
168
 
155
169
void BackgroundListModel::reload() 
162
176
    QStringList dirs = KGlobal::dirs()->findDirs("wallpaper", "");
163
177
    QList<Background *> tmp;
164
178
    foreach (QString file, selected) {
165
 
        if (!contains(file)) {
 
179
        if (!contains(file) && QFile::exists(file)) {
166
180
            tmp << new BackgroundFile(file, m_ratio);
167
181
        }
168
182
    }
170
184
        tmp += findAllBackgrounds(this, dir, m_ratio);
171
185
    }
172
186
    
 
187
    // add new files to dirwatch
 
188
    foreach (Background *b, tmp) {
 
189
        if (!m_dirwatch.contains(b->path())) {
 
190
            m_dirwatch.addFile(b->path());
 
191
        }
 
192
    }
 
193
    
173
194
    if (!tmp.isEmpty()) {
174
195
        beginInsertRows(QModelIndex(), 0, tmp.size() - 1);
175
196
        m_packages = tmp + m_packages;
179
200
 
180
201
void BackgroundListModel::addBackground(const QString& path) {
181
202
    if (!contains(path)) {
 
203
        if (!m_dirwatch.contains(path)) {
 
204
            m_dirwatch.addFile(path);
 
205
        }
182
206
        beginInsertRows(QModelIndex(), 0, 0);
183
207
        m_packages.prepend(new BackgroundFile(path, m_ratio));
184
208
        endInsertRows();
301
325
                   option.rect.width() - x - MARGIN * 2,
302
326
                   maxheight);
303
327
    QString text = title.replace("_", " ");
 
328
    QString authorCaption;
304
329
    if (!author.isEmpty()) {
305
 
        text += "\n" + author;
 
330
        authorCaption = i18nc("Caption to wallpaper preview, %1 author name",
 
331
                              "by %1", author);
 
332
        text += "\n" + authorCaption;
306
333
    }
307
334
    QRect boundingRect = painter->boundingRect(
308
335
        textRect, Qt::AlignVCenter | Qt::TextWordWrap, text);
311
338
        QRect titleRect = painter->boundingRect(boundingRect, Qt::TextWordWrap, title);
312
339
        QRect authorRect(titleRect.bottomLeft(), textRect.size());
313
340
        painter->setFont(KGlobalSettings::smallestReadableFont());
314
 
        painter->drawText(authorRect, Qt::TextWordWrap, "by " + author);
 
341
        painter->drawText(authorRect, Qt::TextWordWrap, authorCaption);
315
342
    }
316
343
 
317
344
    painter->restore();
681
708
{
682
709
    m_preview_timer.stop();
683
710
}
 
711
 
 
712
void BackgroundDialog::removeBackground(const QString &path)
 
713
{
 
714
    m_model->removeBackground(path);
 
715
}