summaryrefslogtreecommitdiffstats
path: root/src/sidebar/sq_mountview.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2025-02-10 15:10:13 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2025-02-13 11:44:42 +0900
commit8f8f84410cc591c85c5e83e0b3efdcda5fdbe42e (patch)
treef273a932ce048ef22ea9d9888b77ea8a2b8f3e33 /src/sidebar/sq_mountview.cpp
parent424635023ee423826de12514b2fec7834b8deb7b (diff)
downloadksquirrel-8f8f8441.tar.gz
ksquirrel-8f8f8441.zip
Rename 'ksquirrel' folder to 'src'
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit 203fcb8d90752b546c672c625927a136b959fcfb)
Diffstat (limited to 'src/sidebar/sq_mountview.cpp')
-rw-r--r--src/sidebar/sq_mountview.cpp247
1 files changed, 247 insertions, 0 deletions
diff --git a/src/sidebar/sq_mountview.cpp b/src/sidebar/sq_mountview.cpp
new file mode 100644
index 0000000..c52b199
--- /dev/null
+++ b/src/sidebar/sq_mountview.cpp
@@ -0,0 +1,247 @@
+/***************************************************************************
+ sq_mountview.cpp - description
+ -------------------
+ begin : ??? Nov 29 2005
+ copyright : (C) 2005 by Baryshev Dmitry
+ email : ksquirrel.iv@gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tdemessagebox.h>
+#include <kmountpoint.h>
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <kautomount.h>
+#include <tdepopupmenu.h>
+
+#include "ksquirrel.h"
+#include "sq_mountview.h"
+#include "sq_mountviewitem.h"
+#include "sq_iconloader.h"
+#include "sq_config.h"
+
+SQ_MountView * SQ_MountView::m_inst = 0;
+
+SQ_MountView::SQ_MountView(TQWidget *parent, const char *name) : TDEListView(parent, name), m_columns(-1)
+{
+ m_inst = this;
+
+ popup = new TDEPopupMenu;
+ id_mount = popup->insertItem(SQ_IconLoader::instance()->loadIcon("drive-harddisk-mounted", TDEIcon::Desktop, TDEIcon::SizeSmall),
+ i18n("Mount"), this, TQ_SLOT(slotMount()));
+ id_unmount = popup->insertItem(SQ_IconLoader::instance()->loadIcon("drive-harddisk-unmounted", TDEIcon::Desktop, TDEIcon::SizeSmall),
+ i18n("Unmount"), this, TQ_SLOT(slotUnmount()));
+ popup->insertItem(SQ_IconLoader::instance()->loadIcon("reload", TDEIcon::Desktop, TDEIcon::SizeSmall),
+ i18n("Refresh"), this, TQ_SLOT(slotRefresh()));
+ popup->insertSeparator();
+ popup->insertItem(i18n("Cancel"));
+
+ connect(this, TQ_SIGNAL(contextMenu(TDEListView *, TQListViewItem *, const TQPoint &)),
+ this, TQ_SLOT(slotContextMenu(TDEListView *, TQListViewItem *, const TQPoint &)));
+ setAcceptDrops(false);
+
+ connect(this, TQ_SIGNAL(returnPressed(TQListViewItem*)), this, TQ_SLOT(slotExecuted(TQListViewItem *)));
+ connect(this, TQ_SIGNAL(clicked(TQListViewItem*)), this, TQ_SLOT(slotExecuted(TQListViewItem *)));
+
+ setShowSortIndicator(true);
+ setAllColumnsShowFocus(true);
+ setSelectionMode(TQListView::Single);
+ setItemsMovable(false);
+
+ // "Name" column will always exist
+ addColumn(i18n("Name"));
+
+ setupColumns();
+}
+
+SQ_MountView::~SQ_MountView()
+{}
+
+void SQ_MountView::slotExecuted(TQListViewItem *i)
+{
+ SQ_MountViewItem *mvi = static_cast<SQ_MountViewItem *>(i);
+
+ if(!mvi)
+ return;
+
+ if(mvi->mounted())
+ emit path(mvi->text(0));
+ else
+ {
+ mountItem = mvi;
+ KAutoMount *mounter = new KAutoMount(false, TQString(), mvi->device(), TQString(), TQString(), false);
+ connect(mounter, TQ_SIGNAL(finished()), this, TQ_SLOT(slotMountFinished()));
+ }
+}
+
+void SQ_MountView::slotMountFinished()
+{
+ mountItem->setMounted(true);
+ emit path(mountItem->text(0));
+}
+
+void SQ_MountView::slotMountError()
+{
+ mountItem->setMounted(false);
+}
+
+void SQ_MountView::reload(bool current)
+{
+ // get currently mounted filesystems
+ KMountPoint::List mt = current ?
+ KMountPoint::currentMountPoints(KMountPoint::NeedMountOptions | KMountPoint::NeedRealDeviceName)
+ : KMountPoint::possibleMountPoints(KMountPoint::NeedMountOptions | KMountPoint::NeedRealDeviceName);
+
+ SQ_MountViewItem *fi;
+ int colum;
+
+ for(KMountPoint::List::iterator it = mt.begin();it != mt.end();++it)
+ {
+ colum = 1;
+
+ if(mounted.find((*it)->mountPoint()) == mounted.end())
+ {
+ mounted.append((*it)->mountPoint());
+
+ // filter out /proc, swap etc.
+ if(!(*it)->mountedFrom().startsWith(TQChar('/')) || !(*it)->mountPoint().startsWith(TQChar('/')))
+ continue;
+
+ fi = new SQ_MountViewItem(this, (*it)->mountPoint());
+ fi->setMounted(current);
+ fi->setDevice((*it)->realDeviceName());
+
+ if(m_columns & OPT_COL_DEVICE)
+ fi->setText(colum++, (*it)->realDeviceName());
+
+ if(m_columns & OPT_COL_FSTYPE)
+ fi->setText(colum++, (*it)->mountType());
+
+ if(m_columns & OPT_COL_OPTIONS)
+ fi->setText(colum, (*it)->mountOptions().join(TQString::fromLatin1(", ")));
+ }
+ }
+}
+
+bool SQ_MountView::exists(const TQString &name)
+{
+ TQListViewItemIterator it(this);
+
+ while(it.current())
+ {
+ SQ_MountViewItem *mvi = static_cast<SQ_MountViewItem *>(it.current());
+
+ if(mvi && mvi->text(0) == name)
+ return true;
+
+ ++it;
+ }
+
+ return false;
+}
+
+void SQ_MountView::setColumns(int cols)
+{
+ if(m_columns == cols)
+ return;
+
+ m_columns = cols;
+
+ int cur = columns() - 1;
+
+ // remove old columns, 0 is always "Name"
+ for(int i = 0;i < cur;i++)
+ removeColumn(1);
+
+ // add new
+ if(m_columns & OPT_COL_DEVICE)
+ addColumn(i18n("Device"));
+
+ if(m_columns & OPT_COL_FSTYPE)
+ addColumn(i18n("FS Type"));
+
+ if(m_columns & OPT_COL_OPTIONS)
+ addColumn(i18n("Options"));
+
+ slotRefresh();
+}
+
+void SQ_MountView::setupColumns()
+{
+ SQ_Config::instance()->setGroup("Sidebar");
+ int p = 0;
+
+ if(SQ_Config::instance()->readBoolEntry("mount_options", false))
+ p |= SQ_MountView::OPT_COL_OPTIONS;
+
+ if(SQ_Config::instance()->readBoolEntry("mount_fstype", true))
+ p |= SQ_MountView::OPT_COL_FSTYPE;
+
+ if(SQ_Config::instance()->readBoolEntry("mount_device", false))
+ p |= SQ_MountView::OPT_COL_DEVICE;
+
+ setColumns(p);
+}
+
+void SQ_MountView::slotContextMenu(TDEListView *, TQListViewItem *i, const TQPoint &p)
+{
+ SQ_MountViewItem *mvi = static_cast<SQ_MountViewItem *>(i);
+
+ citem = mvi;
+
+ popup->setItemEnabled(id_mount, !!mvi);
+ popup->setItemEnabled(id_unmount, !!mvi);
+
+ popup->exec(p);
+}
+
+void SQ_MountView::slotUnmount()
+{
+ if(citem)
+ {
+ KAutoUnmount *mounter = new KAutoUnmount(citem->text(0), TQString());
+ connect(mounter, TQ_SIGNAL(finished()), this, TQ_SLOT(slotUnmountFinished()));
+ }
+}
+
+void SQ_MountView::slotMount()
+{
+ if(citem)
+ {
+ KAutoMount *mounter = new KAutoMount(false, TQString(), citem->device(), TQString(), TQString(), false);
+ connect(mounter, TQ_SIGNAL(finished()), this, TQ_SLOT(slotMountFinished2()));
+// connect(mounter, TQ_SIGNAL(error()), this, TQ_SLOT(slotMountError()));
+ }
+}
+
+void SQ_MountView::slotUnmountFinished()
+{
+ citem->setMounted(false);
+}
+
+void SQ_MountView::slotMountFinished2()
+{
+ citem->setMounted(true);
+}
+
+void SQ_MountView::slotRefresh()
+{
+ clear();
+ mounted.clear();
+ reload();
+ reload(false);
+}
+
+#include "sq_mountview.moc"