~ubuntu-branches/ubuntu/jaunty/kdebase/jaunty-backports

« back to all changes in this revision

Viewing changes to apps/plasma/applets/folderview/folderview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Stalcup
  • Date: 2009-01-08 09:49:20 UTC
  • mfrom: (1.1.22 upstream)
  • Revision ID: james.westby@ubuntu.com-20090108094920-zbm1d1y0y3t5rpff
Tags: 4:4.1.96-0ubuntu1
* New upstream release
* Updated various .install files:
  + dolphin.install
  + kappfinder.install
  + kfind.install
  + konqueror.install
* Bumped build-dep versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <QClipboard>
25
25
#include <QDebug>
26
26
#include <QDesktopServices>
27
 
#include <QDesktopWidget>
28
27
#include <QDrag>
29
28
#include <QGraphicsLinearLayout>
30
29
#include <QGraphicsView>
66
65
#include "dialog.h"
67
66
#include "folderviewadapter.h"
68
67
#include "iconview.h"
 
68
#include "iconwidget.h"
69
69
#include "label.h"
70
70
#include "previewpluginsmodel.h"
71
71
#include "proxymodel.h"
247
247
    setHasConfigurationInterface(true);
248
248
    setAcceptHoverEvents(true);
249
249
    setAcceptDrops(true);
250
 
    resize(600, 400);
251
250
 
252
251
    m_dirModel = new KDirModel(this);
253
252
    m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory | KDirModel::DropOnLocalExecutable);
264
263
        setUrl(KUrl(args.value(0).toString()));
265
264
    }
266
265
 
 
266
    resize(600, 400);
 
267
 
267
268
    // As we use some part of konqueror libkonq must be added to have translations
268
269
    KGlobal::locale()->insertCatalog("libkonq");
269
270
}
279
280
    // Find out about theme changes
280
281
    connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(themeChanged()));
281
282
 
 
283
    // Find out about network availability changes
 
284
    connect(Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)),
 
285
            SLOT(networkStatusChanged(Solid::Networking::Status)));
 
286
 
282
287
    KConfigGroup cg = config();
283
288
    m_customLabel         = cg.readEntry("customLabel", "");
284
289
    m_customIconSize      = cg.readEntry("customIconSize", 0);
311
316
    m_dirModel->setDirLister(lister);
312
317
 
313
318
    if (!m_url.isValid()) {
314
 
        setUrl(cg.readEntry("url", KUrl(isContainment() ? QString("desktop:/") : QDir::homePath())));
 
319
 
 
320
        //FIXME: 4.3 Need to update folderview's description
 
321
        QString path = QDir::homePath();
 
322
        if (isContainment()) {
 
323
            QString desktopPath = KGlobalSettings::desktopPath();
 
324
            QDir desktopFolder(desktopPath);
 
325
 
 
326
            if (desktopPath != QDir::homePath() && desktopFolder.exists()) {
 
327
                path = QString("desktop:/");
 
328
            }
 
329
        }
 
330
        setUrl(cg.readEntry("url", KUrl(path)));
 
331
 
315
332
    } else {
316
333
        KConfigGroup cg = config();
317
334
        cg.writeEntry("url", m_url);
318
335
    }
319
336
 
 
337
    // TODO: 4.3 Check if the URL is a remote URL, and if it is check the network status
 
338
    //       and display a message saying it's not available, instead of trying to open
 
339
    //       the URL and waiting for the job to time out.
320
340
    lister->openUrl(m_url);
321
341
 
322
342
    if (isContainment()) {
362
382
    placesFilter->setSourceModel(m_placesModel);
363
383
    uiLocation.placesCombo->setModel(placesFilter);
364
384
 
365
 
    if (m_url == KUrl("desktop:/")) {
 
385
    QString desktopPath = KGlobalSettings::desktopPath();
 
386
    QDir desktopFolder(desktopPath);
 
387
 
 
388
    bool desktopVisible = desktopPath != QDir::homePath() && desktopFolder.exists();
 
389
    uiLocation.showDesktopFolder->setVisible(desktopVisible);
 
390
 
 
391
    if (desktopVisible && m_url == KUrl("desktop:/")) {
366
392
        uiLocation.showDesktopFolder->setChecked(true);
367
393
        uiLocation.placesCombo->setEnabled(false);
368
394
        uiLocation.lineEdit->setEnabled(false);
467
493
    connect(uiDisplay.previewsAdvanced, SIGNAL(clicked()), this, SLOT(showPreviewConfigDialog()));
468
494
    connect(uiDisplay.showPreviews, SIGNAL(toggled(bool)), uiDisplay.previewsAdvanced, SLOT(setEnabled(bool)));
469
495
 
470
 
    // We can't use KGlobalSettings::desktopPath() here, since it returns the home dir if
471
 
    // the desktop folder doesn't exist.
472
 
    QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
473
 
    if (desktopPath.isEmpty()) {
474
 
        desktopPath = QDir::homePath() + "/Desktop";
475
 
    }
476
 
 
477
 
    // Don't show the warning label if the desktop folder exists
478
 
    if (QFile::exists(desktopPath)) {
479
 
        uiLocation.warningSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
480
 
        uiLocation.warningLabel->setVisible(false);
481
 
    }
482
 
 
483
496
    KConfigGroup cg = config();
484
497
    int filter = cg.readEntry("filter", 0);
485
498
    uiFilter.filterType->setCurrentIndex(filter);
564
577
 
565
578
    const QList<int> iconSizes = QList<int>() << 16 << 22 << 32 << 48 << 64 << 128;
566
579
    int size = iconSizes.at(uiDisplay.sizeSlider->value());
567
 
    if ((m_customIconSize == 0 && size != KIconLoader::global()->currentSize(KIconLoader::Desktop)) ||
568
 
        (m_customIconSize != 0 && size != m_customIconSize))
 
580
    if (size != iconSize().width())
569
581
    {
570
582
        m_customIconSize = size;
571
583
        cg.writeEntry("customIconSize", m_customIconSize);
694
706
                     Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
695
707
    m_iconView->setPalette(palette);
696
708
 
697
 
    const QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DesktopFont);
698
 
    if (m_iconView->font() != font) {
699
 
        m_iconView->setFont(font);
700
 
    }
701
709
    m_iconView->setDrawShadows(m_drawShadows);
702
710
    m_iconView->setIconSize(iconSize());
703
711
    m_iconView->setGridSize(gridSize());
722
730
    m_iconView->setModel(m_model);
723
731
    m_iconView->setItemDelegate(m_delegate);
724
732
    m_iconView->setSelectionModel(m_selectionModel);
 
733
    m_iconView->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DesktopFont));
725
734
 
726
735
    if (!isContainment()) {
727
736
        m_label = new Label(this);
769
778
 
770
779
void FolderView::iconSettingsChanged(int group)
771
780
{
772
 
    if (group == KIconLoader::Desktop)
773
 
    {
774
 
        if (m_iconView) {
775
 
            const int size = (m_customIconSize != 0) ?
776
 
                    m_customIconSize : KIconLoader::global()->currentSize(KIconLoader::Desktop);
777
 
 
778
 
            m_iconView->setIconSize(QSize(size, size));
779
 
        }
 
781
    if (group == KIconLoader::Desktop && m_iconView)
 
782
    {
 
783
        const int size = (m_customIconSize != 0) ?
 
784
                m_customIconSize : KIconLoader::global()->currentSize(KIconLoader::Desktop);
 
785
 
 
786
        m_iconView->setIconSize(QSize(size, size));
 
787
    }
 
788
    else if (group == KIconLoader::Panel && m_listView)
 
789
    {
 
790
        const int size = (m_customIconSize != 0) ?
 
791
                m_customIconSize : KIconLoader::global()->currentSize(KIconLoader::Panel);
 
792
 
 
793
        m_listView->setIconSize(QSize(size, size));
780
794
    }
781
795
}
782
796
 
792
806
        m_iconView->setPalette(palette);
793
807
    }
794
808
 
 
809
    if (m_listView) {
 
810
        updateListViewState();
 
811
    }
 
812
 
795
813
    if (m_label) {
796
814
        QPalette palette = m_label->palette();
797
815
        palette.setColor(QPalette::Text, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
799
817
    }
800
818
}
801
819
 
 
820
void FolderView::networkStatusChanged(Solid::Networking::Status status)
 
821
{
 
822
    if (status == Solid::Networking::Connected && !m_url.isLocalFile() &&
 
823
        m_url.protocol() != "desktop") {
 
824
        refreshIcons();
 
825
    }
 
826
}
 
827
 
802
828
void FolderView::clipboardDataChanged()
803
829
{
804
830
    const QMimeData *mimeData = QApplication::clipboard()->mimeData();
861
887
            }
862
888
            delete m_iconWidget;
863
889
            delete m_dialog;
864
 
            delete m_listView;
865
890
            m_iconWidget = 0;
866
891
            m_dialog = 0;
867
892
            m_listView = 0;
 
893
 
868
894
            if (!isContainment()) {
 
895
                // Give the applet a sane size
869
896
                setupIconView();
870
897
            }
871
898
            setAspectRatioMode(Plasma::IgnoreAspectRatio);
877
904
            m_iconView = 0;
878
905
 
879
906
            // Set up the icon widget
880
 
            m_iconWidget = new Plasma::IconWidget(this);
 
907
            m_iconWidget = new IconWidget(this);
 
908
            m_iconWidget->setModel(m_dirModel);
881
909
            m_iconWidget->setIcon(m_icon.isNull() ? KIcon("user-folder") : m_icon);
882
910
            connect(m_iconWidget, SIGNAL(clicked()), SLOT(iconWidgetClicked()));
883
911
 
889
917
            connect(m_dirModel->dirLister(), SIGNAL(clear()), SLOT(updateIconWidget()));
890
918
 
891
919
            m_listView = new ListView;
 
920
            m_listView->setItemDelegate(m_delegate);
892
921
            m_listView->setModel(m_model);
893
 
            m_listView->setItemDelegate(m_delegate);
894
922
            m_listView->setSelectionModel(m_selectionModel);
895
923
 
896
924
            connect(m_listView, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
904
932
            updateListViewState();
905
933
 
906
934
            m_dialog = new Dialog;
907
 
 
908
 
            QGraphicsScene *scene = new QGraphicsScene(m_dialog);
909
 
            scene->addItem(m_listView);
910
 
 
911
 
            m_dialog->setGraphicsWidget(m_listView);
 
935
            m_dialog->setGraphicsWidget(m_listView); // Ownership is transferred to the scene in the dialog
912
936
 
913
937
            QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, this);
914
938
            layout->setContentsMargins(0, 0, 0, 0);
946
970
    QRect screenRect = c->screenGeometry(screen());
947
971
    m_iconView->setContentsMargins(availRect.x() - screenRect.x(),
948
972
                                   availRect.y() - screenRect.y(),
949
 
                                   availRect.right() - screenRect.right(),
950
 
                                   availRect.bottom() - screenRect.bottom());
 
973
                                   screenRect.right() - availRect.right(),
 
974
                                   screenRect.bottom() - availRect.bottom());
951
975
}
952
976
 
953
977
void FolderView::mousePressEvent(QGraphicsSceneMouseEvent *event)
1340
1364
void FolderView::moveToTrash(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
1341
1365
{
1342
1366
    Q_UNUSED(buttons)
 
1367
    if (m_iconView && m_iconView->renameInProgress()) {
 
1368
        return;
 
1369
    }
1343
1370
 
1344
1371
    KonqOperations::Operation op = (modifiers & Qt::ShiftModifier) ?
1345
1372
            KonqOperations::DEL : KonqOperations::TRASH;
1349
1376
 
1350
1377
void FolderView::deleteSelectedIcons()
1351
1378
{
 
1379
    if (m_iconView && m_iconView->renameInProgress()) {
 
1380
        return;
 
1381
    }
 
1382
 
1352
1383
    KonqOperations::del(view(), KonqOperations::DEL, selectedUrls());
1353
1384
}
1354
1385
 
1525
1556
    Plasma::ToolTipContent data;
1526
1557
    data.setMainText(m_titleText);
1527
1558
    data.setSubText(subText);
1528
 
    data.setImage(m_icon/*.pixmap(IconSize(KIconLoader::Desktop))*/);
 
1559
    data.setImage(m_icon);
1529
1560
    Plasma::ToolTipManager::self()->setContent(m_iconWidget, data);
1530
1561
}
1531
1562
 
1534
1565
    if (m_dialog->isVisible()) {
1535
1566
        m_dialog->hide();
1536
1567
    } else {
1537
 
        int left, top, right, bottom;
1538
 
        m_dialog->getContentsMargins(&left, &top, &right, &bottom);
1539
 
 
1540
 
        const QRect rect = QApplication::desktop()->availableGeometry().adjusted(left, top, -right, -bottom);
1541
 
        m_listView->resize(m_listView->preferredSize().boundedTo(rect.size()));
1542
 
 
1543
 
        m_dialog->resize(m_listView->size().toSize() + QSize(left + right, top + bottom));
1544
 
        m_dialog->move(popupPosition(m_dialog->size()));
1545
 
        m_dialog->show();
 
1568
        m_dialog->show(this);
1546
1569
    }
1547
1570
}
1548
1571
 
1549
1572
QSize FolderView::iconSize() const
1550
1573
{
1551
 
    const int size = (m_customIconSize != 0) ? m_customIconSize : KIconLoader::global()->currentSize(KIconLoader::Desktop);
 
1574
    const int defaultSize = KIconLoader::global()->currentSize(m_listView ? KIconLoader::Panel : KIconLoader::Desktop);
 
1575
    const int size = (m_customIconSize != 0) ? m_customIconSize : defaultSize;
1552
1576
    return QSize(size, size);
1553
1577
}
1554
1578