#include "DesktopViewPlugin.h" #include #include #include #include #include #include "LSession.h" DesktopViewPlugin::DesktopViewPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ this->setLayout( new QVBoxLayout()); this->layout()->setContentsMargins(0,0,0,0); list = new QListWidget(this); list->setUniformItemSizes(true); list->setViewMode(QListView::IconMode); list->setLayoutMode(QListView::Batched); list->setBatchSize(10); //keep it snappy list->setSpacing(2); list->setSelectionBehavior(QAbstractItemView::SelectItems); list->setSelectionMode(QAbstractItemView::ExtendedSelection); list->setStyleSheet( "QListWidget{ background: transparent; border: none; }" ); int icosize = settings->value("IconSize",64).toInt(); list->setIconSize(QSize(icosize,icosize)); list->setUniformItemSizes(true); list->setContextMenuPolicy(Qt::CustomContextMenu); menu = new QMenu(this); menu->addAction( LXDG::findIcon("run-build-file",""), tr("Open"), this, SLOT(runItems()) ); menu->addSeparator(); menu->addAction( LXDG::findIcon("edit-cut",""), tr("Cut"), this, SLOT(cutItems()) ); menu->addAction( LXDG::findIcon("edit-copy",""), tr("Copy"), this, SLOT(copyItems()) ); menu->addSeparator(); menu->addAction( LXDG::findIcon("zoom-in",""), tr("Increase Icons"), this, SLOT(increaseIconSize()) ); menu->addAction( LXDG::findIcon("zoom-out",""), tr("Decrease Icons"), this, SLOT(decreaseIconSize()) ); menu->addSeparator(); menu->addAction( LXDG::findIcon("edit-delete",""), tr("Delete"), this, SLOT(deleteItems()) ); menu->addSeparator(); menu->addAction( LXDG::findIcon("system-search",""), tr("Properties"), this, SLOT(displayProperties()) ); this->layout()->addWidget(list); this->setInitialSize(600,600); watcher = new QFileSystemWatcher(this); watcher->addPath(QDir::homePath()+"/Desktop"); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateContents()) ); connect(list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(runItems()) ); connect(list, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)) ); QTimer::singleShot(0,this, SLOT(updateContents()) ); } DesktopViewPlugin::~DesktopViewPlugin(){ } void DesktopViewPlugin::runItems(){ QList sel = list->selectedItems(); for(int i=0; iwhatsThis()+"\""); } } void DesktopViewPlugin::copyItems(){ QList sel = list->selectedItems(); if(sel.isEmpty()){ return; } //nothing selected QStringList items; //Format the data string for(int i=0; iwhatsThis(); } //Now save that data to the global clipboard QMimeData *dat = new QMimeData; dat->clear(); dat->setData("x-special/lumina-copied-files", items.join("\n").toLocal8Bit()); QApplication::clipboard()->clear(); QApplication::clipboard()->setMimeData(dat); } void DesktopViewPlugin::cutItems(){ QList sel = list->selectedItems(); if(sel.isEmpty()){ return; } //nothing selected QStringList items; //Format the data string for(int i=0; iwhatsThis(); } //Now save that data to the global clipboard QMimeData *dat = new QMimeData; dat->clear(); dat->setData("x-special/lumina-copied-files", items.join("\n").toLocal8Bit()); QApplication::clipboard()->clear(); QApplication::clipboard()->setMimeData(dat); } void DesktopViewPlugin::deleteItems(){ QList sel = list->selectedItems(); for(int i=0; iwhatsThis()); } } void DesktopViewPlugin::showMenu(const QPoint &pos){ //Make sure there is an item underneath the mouse first if(list->itemAt(pos)!=0){ menu->popup(pos); }else{ //Pass the context menu request on to the desktop (emit it from the plugin) emit OpenDesktopMenu(); } } void DesktopViewPlugin::increaseIconSize(){ int icosize = settings->value("IconSize",64).toInt(); icosize+=16; //go in orders of 16 pixels list->setIconSize(QSize(icosize,icosize)); settings->setValue("IconSize",icosize); updateContents(); } void DesktopViewPlugin::decreaseIconSize(){ int icosize = settings->value("IconSize",64).toInt(); if(icosize < 20){ return; } //too small to decrease more icosize-=16; //go in orders of 16 pixels list->setIconSize(QSize(icosize,icosize)); settings->setValue("IconSize",icosize); updateContents(); } void DesktopViewPlugin::updateContents(){ list->clear(); int icosize = settings->value("IconSize",64).toInt(); list->setGridSize(QSize(icosize+8,icosize+4+this->fontMetrics().height())); QDir dir(QDir::homePath()+"/Desktop"); QFileInfoList files = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name | QDir::Type | QDir::DirsFirst); for(int i=0; isetWhatsThis(files[i].absoluteFilePath()); if(files[i].isDir()){ it->setIcon( LXDG::findIcon("folder","") ); it->setText( files[i].fileName() ); }else if(files[i].suffix() == "desktop" ){ bool ok = false; XDGDesktop desk = LXDG::loadDesktopFile(files[i].absoluteFilePath(), ok); if(ok){ it->setIcon( LXDG::findIcon(desk.icon,"unknown") ); if(desk.name.isEmpty()){ it->setText( files[i].fileName() ); }else{ it->setText( desk.name ); } }else{ //Revert back to a standard file handling it->setIcon( LXDG::findMimeIcon(files[i].fileName()) ); it->setText( files[i].fileName() ); } }else{ it->setIcon( LXDG::findMimeIcon( files[i].fileName() ) ); it->setText( files[i].fileName() ); } list->addItem(it); } } void DesktopViewPlugin::displayProperties(){ QList sel = list->selectedItems(); for(int i=0; iwhatsThis()); } }