#include "DesktopViewPlugin.h" #include #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); //int icosize = this->readSetting("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(); if(LUtils::isValidBinary("lumina-fileinfo")){ menu->addAction( LXDG::findIcon("system-search",""), tr("Properties"), this, SLOT(displayProperties()) ); } this->layout()->addWidget(list); this->setInitialSize(600,600); connect(QApplication::instance(), SIGNAL(DesktopFilesChanged()), 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()).isDir()){ QProcess::startDetached("rm -r \""+sel[i]->whatsThis()+"\""); }else{ QFile::remove(sel[i]->whatsThis()); } } } 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 = this->readSetting("IconSize",64).toInt(); icosize+=16; //go in orders of 16 pixels //list->setIconSize(QSize(icosize,icosize)); this->saveSetting("IconSize",icosize); updateContents(); } void DesktopViewPlugin::decreaseIconSize(){ int icosize = this->readSetting("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)); this->saveSetting("IconSize",icosize); updateContents(); } void DesktopViewPlugin::updateContents(){ list->clear(); /*if(imgExtensions.isEmpty()){ QList fmt = QImageReader::supportedImageFormats(); for(int i=0; ireadSetting("IconSize",64).toInt(); QSize gridSZ = QSize(icosize+8,icosize+4+(2*this->fontMetrics().height()) ); //qDebug() << "Icon Size:" << icosize <<"Grid Size:" << gridSZ.width() << gridSZ.height(); list->setGridSize(gridSZ); list->setIconSize(QSize(icosize,icosize)); 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; isetTextAlignment(Qt::AlignCenter); it->setWhatsThis(files[i].absoluteFilePath()); QString txt; if(files[i].isDir()){ it->setIcon( LXDG::findIcon("folder","") ); txt = 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()){ txt = files[i].fileName(); }else{ txt = desk.name; } }else{ //Revert back to a standard file handling it->setIcon( LXDG::findMimeIcon(files[i].fileName()) ); txt = files[i].fileName(); } }else if(LUtils::imageExtensions().contains(files[i].suffix().toLower()) ){ it->setIcon( QIcon( QPixmap(files[i].absoluteFilePath()).scaled(icosize,icosize,Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ) ); txt = files[i].fileName(); }else{ it->setIcon( LXDG::findMimeIcon( files[i].fileName() ) ); txt = files[i].fileName(); } //Now adjust the visible text as necessary based on font/grid sizing it->setToolTip(txt); if(this->fontMetrics().width(txt) > (gridSZ.width()-2) ){ //int dash = this->fontMetrics().width("-"); //Text too long, try to show it on two lines txt = txt.section(" ",0,2).replace(" ","\n"); //First take care of any natural breaks if(txt.contains("\n")){ //need to check each line QStringList txtL = txt.split("\n"); for(int i=0; ifontMetrics().elidedText(txtL[i], Qt::ElideRight, gridSZ.width()); } txt = txtL.join("\n"); }else{ txt = this->fontMetrics().elidedText(txt,Qt::ElideRight, 2*gridSZ.width()); //Now split the line in half for the two lines txt.insert( (txt.count()/2), "\n"); } } it->setText(txt); list->addItem(it); QApplication::processEvents(); //keep the UI snappy } } void DesktopViewPlugin::displayProperties(){ QList sel = list->selectedItems(); for(int i=0; iwhatsThis()); } }