Skip to content

Commit

Permalink
feat: 优化远程服务器功能的实现 (#286)
Browse files Browse the repository at this point in the history
修改了添加分组的操作逻辑
添加了删除服务器的按钮
添加了服务器和分组的分割标签
添加了“添加分组/编辑分组”按钮

Log: 优化远程服务器功能的实现

Signed-off-by: Yutao Meng <mengyutao@deepin.org>
  • Loading branch information
ArchieMeng authored Aug 1, 2023
1 parent d057f5e commit b6f08df
Show file tree
Hide file tree
Showing 24 changed files with 1,192 additions and 585 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ set (DTNG_CPP_FILES
src/main/terminalapplication.cpp
src/main/termproperties.cpp
src/main/dbusmanager.cpp
src/remotemanage/groupconfigoptdlg.cpp
src/remotemanage/remotemanagementpanel.cpp
src/remotemanage/remotemanagementplugn.cpp
src/remotemanage/remotemanagementsearchpanel.cpp
Expand Down
131 changes: 131 additions & 0 deletions src/remotemanage/groupconfigoptdlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2022 ~ 2022 Uniontech Software Technology Co.,Ltd.
*
* Author: Yutao Meng <mengyutao@uniontech.com>
*
* Maintainer: Yutao Meng <mengyutao@uniontech.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 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "groupconfigoptdlg.h"
#include "serverconfigmanager.h"
#include "utils.h"

#include <DSuggestButton>
#include <DVerticalLine>

GroupConfigOptDlg::GroupConfigOptDlg(const QString &groupName, QWidget *parent)
: DAbstractDialog(false, parent),
m_mainLayout(new QVBoxLayout),
m_headLayout(new QHBoxLayout),
m_iconLabel(new DLabel(this)),
m_titleLabel(new DLabel(this)),
m_closeButton(new DWindowCloseButton(this)),
m_groupNameEdit(new DLineEdit(this)),
m_serverList(new ListView(ListType_Remote, this))
{
m_groupNameEdit->setPlaceholderText(tr("Group Name(Required)"));
if (groupName.isEmpty()) {
m_titleLabel->setText(tr("Add Group"));
} else {
m_groupNameEdit->setText(groupName);
m_titleLabel->setText(tr("Edit Group"));
}
m_titleLabel->setAlignment(Qt::AlignCenter);
// 字体
DFontSizeManager::instance()->bind(m_titleLabel, DFontSizeManager::T5, QFont::DemiBold);
// 字色
DPalette palette = m_titleLabel->palette();
QColor color;
if (DApplicationHelper::DarkType == DApplicationHelper::instance()->themeType())
color = QColor::fromRgb(192, 198, 212, 255);
else
color = QColor::fromRgb(0, 26, 46, 255);
palette.setBrush(QPalette::WindowText, color);
m_titleLabel->setPalette(palette);

// 对话框按钮
DPushButton *pCancelButton = new DPushButton(tr("Cancel"));
DSuggestButton *pAddSaveButton = new DSuggestButton(groupName.isEmpty() ? tr("Add") : tr("Save"));
pAddSaveButton->setDefault(true);
connect(pAddSaveButton, &DSuggestButton::clicked, this, [this] {
if (m_groupNameEdit->text().trimmed().isEmpty()) {
m_groupNameEdit->showAlertMessage(tr("Please enter a group name"), m_groupNameEdit);
return;
}
if (m_groupNameEdit->text().trimmed().length() > 30) {
m_groupNameEdit->showAlertMessage(tr("The name should be no more than 30 characters"), m_groupNameEdit);
return;
}

for (int i = 0; i < this->m_serverList->itemList().size(); i++) {
const ItemWidget *itemWidget = m_serverList->itemList().at(i);
ServerConfig *config = ServerConfigManager::instance()->getServerConfig(itemWidget->getFirstText());
ServerConfig *newConfig = new ServerConfig;
*newConfig = *config;
if (itemWidget->isChecked()) {
// 勾选的服务器分配新组名
newConfig->m_group = m_groupNameEdit->text().trimmed();
} else {
// 未勾选的,取消分组
newConfig->m_group = "";
}
ServerConfigManager::instance()->delServerConfig(config);
ServerConfigManager::instance()->saveServerConfig(newConfig);
}
accept();
});
connect(pCancelButton, &DPushButton::clicked, this, [this] {
reject();
});
Utils::setSpaceInWord(pCancelButton);
Utils::setSpaceInWord(pAddSaveButton);
DPalette pa = DApplicationHelper::instance()->palette(pAddSaveButton);
QBrush brush = pa.textLively().color();
pa.setBrush(DPalette::ButtonText, brush);
pAddSaveButton->setPalette(pa);
QHBoxLayout *pBtHbLayout = new QHBoxLayout();
DVerticalLine *line = new DVerticalLine();
line->setFixedSize(3, 28);
pBtHbLayout->setContentsMargins(10, 0, 10, 0);
pBtHbLayout->setSpacing(9);
pBtHbLayout->addWidget(pCancelButton);
pBtHbLayout->addWidget(line);
pBtHbLayout->addWidget(pAddSaveButton);

// 标题栏布局
m_iconLabel->setFixedSize(ICONSIZE_50, ICONSIZE_50);
m_iconLabel->setPixmap(QIcon(QStringLiteral(":/logo/deepin-terminal.svg")).pixmap(ICONSIZE_36, ICONSIZE_36));
m_headLayout->addWidget(m_iconLabel, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_headLayout->addWidget(m_titleLabel, 0, Qt::AlignCenter);
m_headLayout->addWidget(m_closeButton, 0, Qt::AlignRight | Qt::AlignTop);
m_closeButton->setFocusPolicy(Qt::TabFocus);
m_closeButton->setFixedWidth(ICONSIZE_50);
m_closeButton->setIconSize(QSize(ICONSIZE_50, ICONSIZE_50));
connect(m_closeButton, &DWindowCloseButton::clicked, this, [this] {
reject();
});

m_groupNameEdit->setFixedWidth(width());
m_serverList->setMaximumHeight(240);
ServerConfigManager::instance()->refreshServerList(ServerConfigManager::PanelType_Serverlist, m_serverList, "", groupName);

m_mainLayout->addLayout(m_headLayout);
m_mainLayout->addWidget(m_groupNameEdit, 0, Qt::AlignTop);
m_mainLayout->addSpacing(20);
m_mainLayout->addWidget(m_serverList, 0, Qt::AlignTop);
m_mainLayout->addLayout(pBtHbLayout);
setLayout(m_mainLayout);
m_groupNameEdit->setFocus();
}
52 changes: 52 additions & 0 deletions src/remotemanage/groupconfigoptdlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2022 ~ 2022 Uniontech Software Technology Co.,Ltd.
*
* Author: Yutao Meng <mengyutao@uniontech.com>
*
* Maintainer: Yutao Meng <mengyutao@uniontech.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 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "listview.h"

#include <DAbstractDialog>
#include <DApplicationHelper>
#include <DLabel>
#include <DLineEdit>
#include <DFontSizeManager>
#include <DWindowCloseButton>

#include <QHBoxLayout>
#include <QVBoxLayout>

DWIDGET_USE_NAMESPACE


class GroupConfigOptDlg : public DAbstractDialog
{
Q_OBJECT
public:
GroupConfigOptDlg(const QString &groupName = QString(), QWidget *parent = nullptr);

private:
DLabel *m_iconLabel;
DLabel *m_titleLabel;
DLineEdit *m_groupNameEdit;
QVBoxLayout *m_mainLayout;
QHBoxLayout *m_headLayout;
DWindowCloseButton *m_closeButton;
ListView *m_serverList;
};
35 changes: 33 additions & 2 deletions src/remotemanage/remotemanagementpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ void RemoteManagementPanel::showCurSearchResult()

void RemoteManagementPanel::showAddServerConfigDlg()
{
qInfo() << "RemoteManagementPanel show add server config dialog.";
// 判断控件是否有焦点
bool focusState = m_pushButton->hasFocus();
// 弹窗显示
Expand All @@ -164,6 +163,31 @@ void RemoteManagementPanel::showAddServerConfigDlg()
dlg->show();
}

void RemoteManagementPanel::showAddGroupConfigDlg(const QString &groupName)
{
// 判断控件是否有焦点55
bool focusState = m_pushButton->hasFocus();
// 弹窗显示
Service::instance()->setIsDialogShow(window(), true);

GroupConfigOptDlg *dlg = new GroupConfigOptDlg(groupName);
connect(dlg, &ServerConfigOptDlg::finished, this, [ = ](int result) {
// 弹窗隐藏或消失
Service::instance()->setIsDialogShow(window(), false);
// 先判断是否要焦点
if (focusState) {
// 让焦点在平面上
setFocus();
// 添加完,将焦点设置在添加按钮上
m_addGroupButton->setFocus();
}
if (QDialog::Accepted == result) {
refreshPanel();
}
});
dlg->show();
}

void RemoteManagementPanel::initUI()
{
this->setBackgroundRole(QPalette::Base);
Expand All @@ -176,12 +200,16 @@ void RemoteManagementPanel::initUI()
m_searchEdit->setObjectName("RemoteSearchEdit");
m_listWidget = new ListView(ListType_Remote, this);
m_listWidget->setObjectName("RemoteManageListWidget");
m_addGroupButton = new DPushButton(this);
m_addGroupButton->setObjectName("AddServerGroupButton");
m_pushButton = new DPushButton(this);
m_pushButton->setObjectName("RemoteAddPushButton");

m_searchEdit->setFixedHeight(COMMONHEIGHT);
m_searchEdit->setClearButtonEnabled(true);

m_addGroupButton->setFixedHeight(COMMONHEIGHT);
m_addGroupButton->setText(tr("Add Group"));
m_pushButton->setFixedHeight(COMMONHEIGHT);
m_pushButton->setText(tr("Add Server"));

Expand All @@ -194,7 +222,6 @@ void RemoteManagementPanel::initUI()
m_imageLabel->setFixedSize(QSize(88, 88));
m_imageLabel->setPixmap(DHiDPIHelper::loadNxPixmap(":/other/server_group.svg"));


QHBoxLayout *hlayout = new QHBoxLayout();
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->addSpacing(SPACEWIDTH);
Expand Down Expand Up @@ -228,6 +255,8 @@ void RemoteManagementPanel::initUI()
btnLayout->addSpacing(SPACEWIDTH);
btnLayout->addWidget(m_pushButton);
btnLayout->addSpacing(SPACEWIDTH);
btnLayout->addWidget(m_addGroupButton);
btnLayout->addSpacing(SPACEWIDTH);
btnLayout->setSpacing(0);
btnLayout->setMargin(0);

Expand All @@ -244,8 +273,10 @@ void RemoteManagementPanel::initUI()

connect(m_searchEdit, &DSearchEdit::returnPressed, this, &RemoteManagementPanel::showCurSearchResult);
connect(m_pushButton, &DPushButton::clicked, this, &RemoteManagementPanel::showAddServerConfigDlg);
connect(m_addGroupButton, &DPushButton::clicked, this, [this] { showAddGroupConfigDlg(); });
connect(m_listWidget, &ListView::itemClicked, this, &RemoteManagementPanel::onItemClicked);
connect(m_listWidget, &ListView::groupClicked, this, &RemoteManagementPanel::showGroupPanel);
connect(m_listWidget, &ListView::groupModify, this, &RemoteManagementPanel::showAddGroupConfigDlg);
connect(m_listWidget, &ListView::listItemCountChange, this, &RemoteManagementPanel::refreshSearchState);
connect(ServerConfigManager::instance(), &ServerConfigManager::refreshList, this, [ = ]() {
if (m_isShow)
Expand Down
6 changes: 6 additions & 0 deletions src/remotemanage/remotemanagementpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "commonpanel.h"
#include "serverconfigoptdlg.h"
#include "groupconfigoptdlg.h"
#include "listview.h"

#include <QWidget>
Expand Down Expand Up @@ -74,6 +75,11 @@ public slots:
* @author ut000610 daizhengwen
*/
void showAddServerConfigDlg();
/**
* @brief 显示远程管理添加分组配置界面
* @author Archie Meng
*/
void showAddGroupConfigDlg(const QString &groupName = QStringLiteral(""));
/**
* @brief 刷新远程管理搜索状态
* @author ut000610 daizhengwen
Expand Down
37 changes: 37 additions & 0 deletions src/remotemanage/serverconfigmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ void ServerConfigManager::settServerConfig(USettings &commandsSettings, const QS
commandsSettings.endGroup();
}

void ServerConfigManager::fillServerList(ListView *listview, const QString &groupName)
{
listview->clearData();
if (m_serverConfigs[groupName].length() > 0) {
for (ServerConfig *item : m_serverConfigs[groupName]) {
listview->addItem(ItemFuncType_UngroupedItem, item->m_serverName, QString("%1@%2").arg(item->m_userName).arg(item->m_address));
}
if (!groupName.isEmpty()) {
for (ItemWidget *item: listview->itemList()) {
item->setChecked(true);
}
}
}
}

void ServerConfigManager::fillManagePanel(ListView *listview)
{
qInfo() << "ServerConfigManager fill data to manage panel.";
Expand All @@ -68,6 +83,9 @@ void ServerConfigManager::fillManagePanel(ListView *listview)
}
}
}
// 添加分组和服务器的分割标题
listview->addItem(ItemFuncType_GroupLabel, tr("Groups"));
listview->addItem(ItemFuncType_ItemLabel, tr("Servers"));
}

void ServerConfigManager::fillSearchPanel(ListView *listview, const QString &filter, const QString &group)
Expand Down Expand Up @@ -275,6 +293,22 @@ void ServerConfigManager::saveServerConfig(ServerConfig *config)

}

void ServerConfigManager::delServerGroupConfig(const QString &key)
{
if (m_serverConfigs.contains(key)) {
for (ServerConfig *config : m_serverConfigs[key]) {
ServerConfig *newConfig = new ServerConfig;
*newConfig = *config;
newConfig->m_group = QStringLiteral("");
delServerConfig(config);
saveServerConfig(newConfig);
}
}
else {
qInfo() << Q_FUNC_INFO << "Cannot find group " << key;
}
}

void ServerConfigManager::delServerConfig(ServerConfig *config)
{
// 防止重复删除
Expand Down Expand Up @@ -341,6 +375,9 @@ void ServerConfigManager::refreshServerList(PanelType type, ListView *listview,
case PanelType_Search:
fillSearchPanel(listview, filter, group);
break;
case PanelType_Serverlist:
fillServerList(listview, group);
break;
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/remotemanage/serverconfigmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class ServerConfigManager : public QObject
// 分组界面
PanelType_Group,
// 搜索界面
PanelType_Search
PanelType_Search,
// 添加分组服务器界面
PanelType_Serverlist
};

static ServerConfigManager *instance();
Expand All @@ -76,6 +78,8 @@ class ServerConfigManager : public QObject
* @param config 服务器配置
*/
void saveServerConfig(ServerConfig *config);
void delServerConfig(const QString &key) { delServerConfig(getServerConfig(key)); }
void delServerGroupConfig(const QString &key);
/**
* @brief 删除服务器配置
* @author ut000610 daizhengwen
Expand Down Expand Up @@ -214,6 +218,11 @@ public slots:
* @param config 服务器配置
*/
inline void settServerConfig(USettings &commandsSettings, const QString &strGroupName, ServerConfig *config);
/**
* @brief 初始化服务器列表
* @param listview 需要填充的列表
*/
void fillServerList(ListView *listview, const QString &groupName);
/**
* @brief 初始化主界面,将数据填充进去
* @author ut000610 戴正文
Expand Down
Loading

0 comments on commit b6f08df

Please sign in to comment.