Skip to content

Commit 3765f94

Browse files
committed
Plugins::FileTransfer: add local file browser
1 parent 4d043ad commit 3765f94

5 files changed

Lines changed: 287 additions & 6 deletions

File tree

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,168 @@
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+
, m_pModelLocalDir(new QFileSystemModel(this))
16+
, m_pModelLocalFile(new QFileSystemModel(this))
1017
{
18+
bool check = false;
1119
ui->setupUi(this);
20+
21+
m_pModelLocalDir->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
22+
ui->treeLocal->setModel(m_pModelLocalDir);
23+
ui->treeLocal->setContextMenuPolicy(Qt::CustomContextMenu);
24+
check = connect(ui->treeLocal, &QTreeView::clicked,
25+
this, &CFrmFileTransfer::slotTreeLocalClicked);
26+
Q_ASSERT(check);
27+
SetLocalRoot(QString());
28+
ui->treeLocal->setHeaderHidden(true);
29+
// 注意:必须在 setModel 之后才会生效
30+
ui->treeLocal->header()->hideSection(1);
31+
ui->treeLocal->header()->hideSection(2);
32+
ui->treeLocal->header()->hideSection(3);
33+
34+
m_pModelLocalFile->setFilter(QDir::Files);
35+
ui->tabLocal->setModel(m_pModelLocalFile);
36+
ui->tabLocal->setContextMenuPolicy(Qt::CustomContextMenu);
37+
ui->tabLocal->setShowGrid(false);
38+
ui->tabLocal->verticalHeader()->hide();
39+
ui->tabLocal->horizontalHeader()->setSectionResizeMode(
40+
QHeaderView::ResizeToContents);
1241
}
1342

1443
CFrmFileTransfer::~CFrmFileTransfer()
1544
{
1645
delete ui;
1746
}
47+
48+
int CFrmFileTransfer::SetLocalRoot(const QString &root)
49+
{
50+
auto index = m_pModelLocalDir->setRootPath(root);
51+
ui->treeLocal->setRootIndex(index);
52+
slotTreeLocalClicked(index);
53+
return 0;
54+
}
55+
56+
QString CFrmFileTransfer::GetLocalRoot() const
57+
{
58+
return m_pModelLocalDir->rootPath();
59+
}
60+
61+
void CFrmFileTransfer::slotTreeLocalClicked(const QModelIndex &index)
62+
{
63+
QString szPath = m_pModelLocalDir->filePath(index);
64+
if(szPath.isEmpty()) return;
65+
if(-1 == ui->cbLocal->findText(szPath))
66+
ui->cbLocal->addItem(szPath);
67+
ui->cbLocal->setCurrentText(szPath);
68+
QModelIndex idx = m_pModelLocalFile->setRootPath(szPath);
69+
ui->tabLocal->setRootIndex(idx);
70+
}
71+
72+
void CFrmFileTransfer::on_cbLocal_editTextChanged(const QString &text)
73+
{
74+
qDebug(log) << Q_FUNC_INFO << text;
75+
auto idx = m_pModelLocalDir->index(text);
76+
if(!idx.isValid()) return;
77+
if(text.length() > 1 && (text.right(1) == '/' || text.right(1) == '\\')) return;
78+
ui->treeLocal->setCurrentIndex(idx);
79+
slotTreeLocalClicked(idx);
80+
}
81+
82+
void CFrmFileTransfer::on_treeLocal_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(ui->treeLocal->mapToGlobal(pos));
95+
}
96+
97+
void CFrmFileTransfer::on_tabLocal_customContextMenuRequested(const QPoint &pos)
98+
{
99+
qDebug(log) << Q_FUNC_INFO;
100+
QMenu menu;
101+
menu.addAction(QIcon::fromTheme("file-open"), tr("Open"),
102+
this, SLOT(slotTabLocalOpen()));
103+
menu.addAction(QIcon::fromTheme("file-edit"), tr("Edit"),
104+
this, SLOT(slotTabLocalEdit()));
105+
menu.addAction(QIcon::fromTheme("remove"), tr("Delete"),
106+
this, SLOT(slotTabLocalDelete()));
107+
menu.addAction(tr("Rename"),
108+
this, SLOT(slotTabLocalRename()));
109+
menu.exec(ui->tabLocal->mapToGlobal(pos));
110+
}
111+
112+
void CFrmFileTransfer::slotTreeLocalOpen()
113+
{
114+
auto idx = ui->treeLocal->currentIndex();
115+
auto szPath = m_pModelLocalDir->filePath(idx);
116+
QDesktopServices::openUrl(QUrl(szPath));
117+
}
118+
119+
void CFrmFileTransfer::slotTreeLocalNew()
120+
{
121+
QString szName = QInputDialog::getText(this, tr("New foler"), tr("Folder name:"));
122+
if(szName.isEmpty()) return;
123+
auto idx = ui->treeLocal->currentIndex();
124+
m_pModelLocalDir->mkdir(idx, szName);
125+
}
126+
127+
void CFrmFileTransfer::slotTreeLocalDelete()
128+
{
129+
auto idx = ui->treeLocal->currentIndex();
130+
m_pModelLocalDir->remove(idx);
131+
}
132+
133+
void CFrmFileTransfer::slotTreeLocalRename()
134+
{
135+
}
136+
137+
void CFrmFileTransfer::slotTreeLocalUpload()
138+
{
139+
140+
}
141+
142+
void CFrmFileTransfer::slotTreeLocalAddToList()
143+
{
144+
145+
}
146+
147+
void CFrmFileTransfer::slotTabLocalOpen()
148+
{
149+
auto idx = ui->tabLocal->currentIndex();
150+
auto szPath = m_pModelLocalFile->filePath(idx);
151+
QDesktopServices::openUrl(QUrl(szPath));
152+
}
153+
154+
void CFrmFileTransfer::slotTabLocalEdit()
155+
{
156+
157+
}
158+
159+
void CFrmFileTransfer::slotTabLocalDelete()
160+
{
161+
auto idx = ui->tabLocal->currentIndex();
162+
m_pModelLocalDir->remove(idx);
163+
}
164+
165+
void CFrmFileTransfer::slotTabLocalRename()
166+
{
167+
168+
}

Plugins/FileTransfer/FrmFileTransfer.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <QWidget>
6+
#include <QFileSystemModel>
67

78
namespace Ui {
89
class CFrmFileTransfer;
@@ -14,8 +15,37 @@ class CFrmFileTransfer : public QWidget
1415

1516
public:
1617
explicit CFrmFileTransfer(QWidget *parent = nullptr);
17-
~CFrmFileTransfer();
18+
virtual ~CFrmFileTransfer();
19+
20+
Q_SIGNALS:
21+
void sigUpload(const QString& source, const QString& destination);
1822

23+
private:
24+
//! Set local root path
25+
int SetLocalRoot(const QString &root);
26+
//! Get local root path
27+
[[nodiscard]] QString GetLocalRoot() const;
28+
29+
private Q_SLOTS:
30+
void slotTreeLocalClicked(const QModelIndex &index);
31+
void slotTreeLocalUpload();
32+
void slotTreeLocalAddToList();
33+
void slotTreeLocalOpen();
34+
void slotTreeLocalNew();
35+
void slotTreeLocalRename();
36+
void slotTreeLocalDelete();
37+
38+
void slotTabLocalOpen();
39+
void slotTabLocalEdit();
40+
void slotTabLocalRename();
41+
void slotTabLocalDelete();
42+
43+
void on_treeLocal_customContextMenuRequested(const QPoint &pos);
44+
void on_tabLocal_customContextMenuRequested(const QPoint &pos);
45+
void on_cbLocal_editTextChanged(const QString &arg1);
46+
1947
private:
2048
Ui::CFrmFileTransfer *ui;
49+
QFileSystemModel* m_pModelLocalDir;
50+
QFileSystemModel* m_pModelLocalFile;
2151
};

Plugins/FileTransfer/FrmFileTransfer.ui

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,110 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>400</width>
10-
<height>300</height>
9+
<width>491</width>
10+
<height>295</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<layout class="QVBoxLayout" name="verticalLayout_2">
19+
<item>
20+
<layout class="QHBoxLayout" name="horizontalLayout">
21+
<item>
22+
<widget class="QLabel" name="label">
23+
<property name="text">
24+
<string>Local:</string>
25+
</property>
26+
</widget>
27+
</item>
28+
<item>
29+
<widget class="QComboBox" name="cbLocal">
30+
<property name="sizePolicy">
31+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
32+
<horstretch>0</horstretch>
33+
<verstretch>0</verstretch>
34+
</sizepolicy>
35+
</property>
36+
<property name="editable">
37+
<bool>true</bool>
38+
</property>
39+
</widget>
40+
</item>
41+
</layout>
42+
</item>
43+
<item>
44+
<widget class="QTreeView" name="treeLocal">
45+
<property name="sizePolicy">
46+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
47+
<horstretch>0</horstretch>
48+
<verstretch>0</verstretch>
49+
</sizepolicy>
50+
</property>
51+
</widget>
52+
</item>
53+
<item>
54+
<widget class="QTableView" name="tabLocal"/>
55+
</item>
56+
</layout>
57+
</item>
58+
<item row="0" column="1">
59+
<layout class="QVBoxLayout" name="verticalLayout">
60+
<item>
61+
<layout class="QHBoxLayout" name="horizontalLayout_2">
62+
<item>
63+
<widget class="QLabel" name="label_2">
64+
<property name="text">
65+
<string>Remote:</string>
66+
</property>
67+
</widget>
68+
</item>
69+
<item>
70+
<widget class="QComboBox" name="cbRemote">
71+
<property name="sizePolicy">
72+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
73+
<horstretch>0</horstretch>
74+
<verstretch>0</verstretch>
75+
</sizepolicy>
76+
</property>
77+
<property name="editable">
78+
<bool>true</bool>
79+
</property>
80+
</widget>
81+
</item>
82+
</layout>
83+
</item>
84+
<item>
85+
<widget class="QTreeView" name="tvRemote"/>
86+
</item>
87+
<item>
88+
<widget class="QTableWidget" name="tabRemote"/>
89+
</item>
90+
</layout>
91+
</item>
92+
<item row="1" column="0" colspan="2">
93+
<widget class="QTabWidget" name="tabWidget">
94+
<property name="tabPosition">
95+
<enum>QTabWidget::TabPosition::South</enum>
96+
</property>
97+
<property name="currentIndex">
98+
<number>1</number>
99+
</property>
100+
<widget class="QWidget" name="tab">
101+
<attribute name="title">
102+
<string>Tab 1</string>
103+
</attribute>
104+
</widget>
105+
<widget class="QWidget" name="tab_2">
106+
<attribute name="title">
107+
<string>Tab 2</string>
108+
</attribute>
109+
</widget>
110+
</widget>
111+
</item>
112+
</layout>
16113
</widget>
17114
<resources/>
18115
<connections/>

Plugins/FileTransfer/PluginFileTransfer.cpp

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

4+
#include <QApplication>
5+
#include <QStyle>
46
#include <QLoggingCategory>
57
#include "PluginFileTransfer.h"
68
#include "OperateFileTransfer.h"
@@ -51,6 +53,7 @@ const QString CPluginFileTransfer::Version() const
5153
const QIcon CPluginFileTransfer::Icon() const
5254
{
5355
return QIcon::fromTheme("system-file-manager");
56+
//return QApplication::style()->standardIcon(QStyle::SP_FileIcon);
5457
}
5558

5659
COperate *CPluginFileTransfer::OnCreateOperate(const QString &szId)

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)