Skip to content

Commit dcca3ef

Browse files
committed
Plugins::FileTransfer: add menu
1 parent 112c8d2 commit dcca3ef

3 files changed

Lines changed: 86 additions & 9 deletions

File tree

Plugins/FileTransfer/FrmFileTransfer.cpp

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
22
// Author Kang Lin <kl222@126.com>
33

4+
#include <QInputDialog>
5+
#include <QMenu>
6+
#include <QDesktopServices>
7+
#include <QLoggingCategory>
48
#include "FrmFileTransfer.h"
59
#include "ui_FrmFileTransfer.h"
610

11+
static Q_LOGGING_CATEGORY(log, "FileTransfer.Widget")
712
CFrmFileTransfer::CFrmFileTransfer(QWidget *parent)
813
: QWidget(parent)
914
, ui(new Ui::CFrmFileTransfer)
@@ -15,11 +20,11 @@ CFrmFileTransfer::CFrmFileTransfer(QWidget *parent)
1520

1621
m_pModelLocalDir->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
1722
ui->tvLocal->setModel(m_pModelLocalDir);
23+
ui->tvLocal->setContextMenuPolicy(Qt::CustomContextMenu);
1824
check = connect(ui->tvLocal, &QTreeView::clicked,
1925
this, &CFrmFileTransfer::slotLocalClicked);
2026
Q_ASSERT(check);
21-
m_pModelLocalDir->setRootPath("");
22-
ui->tvLocal->setRootIndex(m_pModelLocalDir->index(""));
27+
SetLocalRoot("");
2328
ui->tvLocal->setHeaderHidden(true);
2429
// 注意:必须在 setModel 之后才会生效
2530
ui->tvLocal->header()->hideSection(1);
@@ -28,6 +33,7 @@ CFrmFileTransfer::CFrmFileTransfer(QWidget *parent)
2833

2934
m_pModelLocalFile->setFilter(QDir::Files);
3035
ui->tabLocal->setModel(m_pModelLocalFile);
36+
ui->tabLocal->setContextMenuPolicy(Qt::CustomContextMenu);
3137
ui->tabLocal->setShowGrid(false);
3238
ui->tabLocal->verticalHeader()->hide();
3339
ui->tabLocal->horizontalHeader()->setSectionResizeMode(
@@ -43,6 +49,7 @@ int CFrmFileTransfer::SetLocalRoot(const QString &root)
4349
{
4450
auto index = m_pModelLocalDir->setRootPath(root);
4551
ui->tvLocal->setRootIndex(index);
52+
slotLocalClicked(index);
4653
return 0;
4754
}
4855

@@ -54,16 +61,76 @@ QString CFrmFileTransfer::GetLocalRoot() const
5461
void CFrmFileTransfer::slotLocalClicked(const QModelIndex &index)
5562
{
5663
QString szPath = m_pModelLocalDir->filePath(index);
64+
if(szPath.isEmpty()) return;
5765
if(-1 == ui->cbLocal->findText(szPath))
5866
ui->cbLocal->addItem(szPath);
5967
ui->cbLocal->setCurrentText(szPath);
6068
QModelIndex idx = m_pModelLocalFile->setRootPath(szPath);
6169
ui->tabLocal->setRootIndex(idx);
6270
}
6371

64-
void CFrmFileTransfer::on_cbLocal_currentTextChanged(const QString &text)
72+
void CFrmFileTransfer::on_cbLocal_editTextChanged(const QString &text)
6573
{
74+
qDebug(log) << Q_FUNC_INFO << text;
6675
auto idx = m_pModelLocalDir->index(text);
76+
if(!idx.isValid()) return;
77+
if(text.length() > 1 && (text.right(1) == '/' || text.right(1) == '\\')) return;
6778
ui->tvLocal->setCurrentIndex(idx);
6879
slotLocalClicked(idx);
6980
}
81+
82+
void CFrmFileTransfer::on_tvLocal_customContextMenuRequested(const QPoint &pos)
83+
{
84+
qDebug(log) << Q_FUNC_INFO;
85+
QMenu menu;
86+
menu.addAction(QIcon::fromTheme("folder-open"), tr("Open"),
87+
this, SLOT(slotTreeLocalOpen()));
88+
menu.addAction(QIcon::fromTheme("document-new"), tr("New folder"),
89+
this, SLOT(slotTreeLocalNew()));
90+
menu.addAction(QIcon::fromTheme("remove"), tr("Delete"),
91+
this, SLOT(slotTreeLocalDelete()));
92+
menu.addAction(tr("Rename"),
93+
this, SLOT(slotTreeLocalRename()));
94+
menu.exec(mapToGlobal(pos));
95+
}
96+
97+
void CFrmFileTransfer::on_tabLocal_customContextMenuRequested(const QPoint &pos)
98+
{
99+
qDebug(log) << Q_FUNC_INFO;
100+
}
101+
102+
void CFrmFileTransfer::slotTreeLocalOpen()
103+
{
104+
auto idx = ui->tvLocal->currentIndex();
105+
auto szPath = m_pModelLocalDir->filePath(idx);
106+
QDesktopServices::openUrl(QUrl(szPath));
107+
}
108+
109+
void CFrmFileTransfer::slotTreeLocalNew()
110+
{
111+
QString szName = QInputDialog::getText(this, tr("New foler"), tr("Folder name:"));
112+
if(szName.isEmpty()) return;
113+
auto idx = ui->tvLocal->currentIndex();
114+
m_pModelLocalDir->mkdir(idx, szName);
115+
}
116+
117+
void CFrmFileTransfer::slotTreeLocalDelete()
118+
{
119+
auto idx = ui->tvLocal->currentIndex();
120+
m_pModelLocalDir->remove(idx);
121+
}
122+
123+
void CFrmFileTransfer::slotTreeLocalRename()
124+
{
125+
126+
}
127+
128+
void CFrmFileTransfer::slotTreeLocalUpload()
129+
{
130+
131+
}
132+
133+
void CFrmFileTransfer::slotTreeLocalAddToList()
134+
{
135+
136+
}

Plugins/FileTransfer/FrmFileTransfer.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class CFrmFileTransfer : public QWidget
1616
public:
1717
explicit CFrmFileTransfer(QWidget *parent = nullptr);
1818
virtual ~CFrmFileTransfer();
19+
20+
Q_SIGNALS:
21+
void sigUpload(const QString& source, const QString& destination);
1922

2023
private:
2124
//! Set local root path
@@ -25,9 +28,16 @@ class CFrmFileTransfer : public QWidget
2528

2629
private Q_SLOTS:
2730
void slotLocalClicked(const QModelIndex &index);
28-
29-
void on_cbLocal_currentTextChanged(const QString &text);
30-
31+
void slotTreeLocalUpload();
32+
void slotTreeLocalAddToList();
33+
void slotTreeLocalOpen();
34+
void slotTreeLocalNew();
35+
void slotTreeLocalRename();
36+
void slotTreeLocalDelete();
37+
void on_tvLocal_customContextMenuRequested(const QPoint &pos);
38+
void on_tabLocal_customContextMenuRequested(const QPoint &pos);
39+
void on_cbLocal_editTextChanged(const QString &arg1);
40+
3141
private:
3242
Ui::CFrmFileTransfer *ui;
3343
QFileSystemModel* m_pModelLocalDir;

share/metainfo/io.github.KangLin.RabbitRemoteControl.metainfo.xml.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
<description>
1515
<p>Rabbit remote control is a open-source, cross-platform, multi-protocol remote control software.</p>
1616
<p><em>Allows you to use any device and system in anywhere and remotely manage any device and system in any way. </em></p>
17-
<p>It include remote desktop, remote control, remote terminal, player, network tools etc functions.</p>
17+
<p>It include remote desktop, remote control, remote terminal, file transfers, player, network tools etc functions.</p>
1818

1919
<p xml:lang="zh_CN">玉兔远程控制是一个开源、跨平台、多协议的远程控制软件。</p>
2020
<p xml:lang="zh_CN">能让你在<em>任何地方</em>使用<em>任何设备和系统</em>通过<em>任意方式</em>远程管理任意<em>设备和系统</em>。</p>
21-
<p xml:lang="zh_CN">它包括远程桌面、远程控制、远程终端、播放器、网络工具等功能。</p>
21+
<p xml:lang="zh_CN">它包括远程桌面、远程控制、远程终端、文件传输、播放器、网络工具等功能。</p>
2222

2323
<p xml:lang="zh_TW">玉兔遠程控製是一個開源、跨平臺、多協議的遠程控製軟件。</p>
2424
<p xml:lang="zh_TW">能讓你在<em>任何地方</em>使用<em>任何設備和系統</em>通過<em>任意方式</em>遠程管理任意<em>設備和系統</em>。</p>
25-
<p xml:lang="zh_TW">它包括遠程桌面、遠程控製、遠程終端、播放器、網絡工具等功能。</p>
25+
<p xml:lang="zh_TW">它包括遠程桌面、遠程控製、遠程終端、文件傳輸、播放器、網絡工具等功能。</p>
2626
</description>
2727

2828
<developer id="io.github.KangLin">

0 commit comments

Comments
 (0)