Merge pull request #1183 from flylai/dev-log-copy-selected

feat: support copying selected logs
This commit is contained in:
flylai 2020-12-24 15:07:29 +08:00 committed by GitHub
commit 88a2b51da3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 38 deletions

View File

@ -192,6 +192,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QvStateObject("Ma
// //
// Actions for right click the log text browser // Actions for right click the log text browser
// //
logRCM_Menu->addAction(action_RCM_CopySelected);
logRCM_Menu->addAction(action_RCM_CopyRecentLogs); logRCM_Menu->addAction(action_RCM_CopyRecentLogs);
logRCM_Menu->addSeparator(); logRCM_Menu->addSeparator();
logRCM_Menu->addAction(action_RCM_SwitchCoreLog); logRCM_Menu->addAction(action_RCM_SwitchCoreLog);
@ -200,6 +201,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QvStateObject("Ma
connect(action_RCM_SwitchCoreLog, &QAction::triggered, [this] { masterLogBrowser->setDocument(vCoreLogDocument); }); connect(action_RCM_SwitchCoreLog, &QAction::triggered, [this] { masterLogBrowser->setDocument(vCoreLogDocument); });
connect(action_RCM_SwitchQv2rayLog, &QAction::triggered, [this] { masterLogBrowser->setDocument(qvLogDocument); }); connect(action_RCM_SwitchQv2rayLog, &QAction::triggered, [this] { masterLogBrowser->setDocument(qvLogDocument); });
connect(action_RCM_CopyRecentLogs, &QAction::triggered, this, &MainWindow::Action_CopyRecentLogs); connect(action_RCM_CopyRecentLogs, &QAction::triggered, this, &MainWindow::Action_CopyRecentLogs);
connect(action_RCM_CopySelected, &QAction::triggered, masterLogBrowser, &QTextBrowser::copy);
// //
speedChartWidget->setContextMenuPolicy(Qt::CustomContextMenu); speedChartWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(speedChartWidget, &QWidget::customContextMenuRequested, [this](const QPoint &) { graphWidgetMenu->popup(QCursor::pos()); }); connect(speedChartWidget, &QWidget::customContextMenuRequested, [this](const QPoint &) { graphWidgetMenu->popup(QCursor::pos()); });
@ -282,13 +284,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QvStateObject("Ma
// Find and start if there is an auto-connection // Find and start if there is an auto-connection
const auto connectionStarted = StartAutoConnectionEntry(); const auto connectionStarted = StartAutoConnectionEntry();
if (!connectionStarted && !ConnectionManager->GetConnections().isEmpty()) if (!connectionStarted && !ConnectionManager->GetConnections().isEmpty())
{ {
// Select the first connection. // Select the first connection.
const auto groups = ConnectionManager->AllGroups(); const auto groups = ConnectionManager->AllGroups();
if (!groups.isEmpty()) if (!groups.isEmpty())
{ {
const auto connections = ConnectionManager->GetConnections(groups.first()); const auto connections = ConnectionManager->GetConnections(groups.first());
if (!connections.empty()) if (!connections.empty())
{ {
const auto index = modelHelper->GetConnectionPairIndex({ connections.first(), groups.first() }); const auto index = modelHelper->GetConnectionPairIndex({ connections.first(), groups.first() });
@ -526,32 +528,32 @@ void MainWindow::on_connectionTreeView_customContextMenuRequested(const QPoint &
void MainWindow::Action_DeleteConnections() void MainWindow::Action_DeleteConnections()
{ {
QList<ConnectionGroupPair> connlist; QList<ConnectionGroupPair> connlist;
QList<GroupId> groupsList; QList<GroupId> groupsList;
for (const auto &item : connectionTreeView->selectionModel()->selectedIndexes()) for (const auto &item : connectionTreeView->selectionModel()->selectedIndexes())
{ {
const auto widget = GetIndexWidget(item); const auto widget = GetIndexWidget(item);
if (!widget) if (!widget)
continue; continue;
const auto identifier = widget->Identifier(); const auto identifier = widget->Identifier();
if (widget->IsConnection()) if (widget->IsConnection())
{ {
// Simply add the connection id // Simply add the connection id
connlist.append(identifier); connlist.append(identifier);
continue; continue;
} }
for (const auto &conns : ConnectionManager->GetConnections(identifier.groupId)) for (const auto &conns : ConnectionManager->GetConnections(identifier.groupId))
{ {
connlist.append(ConnectionGroupPair{ conns, identifier.groupId }); connlist.append(ConnectionGroupPair{ conns, identifier.groupId });
} }
const auto message = tr("Do you want to remove this group as well?") + NEWLINE + tr("Group: ") + GetDisplayName(identifier.groupId); const auto message = tr("Do you want to remove this group as well?") + NEWLINE + tr("Group: ") + GetDisplayName(identifier.groupId);
if (QvMessageBoxAsk(this, tr("Removing Connection"), message) == Yes) if (QvMessageBoxAsk(this, tr("Removing Connection"), message) == Yes)
{ {
groupsList << identifier.groupId; groupsList << identifier.groupId;
} }
} }
const auto strRemoveConnTitle = tr("Removing Connection(s)", "", connlist.count()); const auto strRemoveConnTitle = tr("Removing Connection(s)", "", connlist.count());
@ -565,11 +567,11 @@ void MainWindow::Action_DeleteConnections()
{ {
ConnectionManager->RemoveConnectionFromGroup(conn.connectionId, conn.groupId); ConnectionManager->RemoveConnectionFromGroup(conn.connectionId, conn.groupId);
} }
for (const auto &group : groupsList) for (const auto &group : groupsList)
{ {
ConnectionManager->DeleteGroup(group); ConnectionManager->DeleteGroup(group);
} }
} }
void MainWindow::on_importConfigButton_clicked() void MainWindow::on_importConfigButton_clicked()

View File

@ -151,6 +151,7 @@ class MainWindow
DECL_ACTION(logRCM_Menu, action_RCM_SwitchCoreLog); DECL_ACTION(logRCM_Menu, action_RCM_SwitchCoreLog);
DECL_ACTION(logRCM_Menu, action_RCM_SwitchQv2rayLog); DECL_ACTION(logRCM_Menu, action_RCM_SwitchQv2rayLog);
DECL_ACTION(logRCM_Menu, action_RCM_CopyRecentLogs); DECL_ACTION(logRCM_Menu, action_RCM_CopyRecentLogs);
DECL_ACTION(logRCM_Menu, action_RCM_CopySelected);
#undef DECL_ACTION #undef DECL_ACTION
QTextDocument *vCoreLogDocument = new QTextDocument(this); QTextDocument *vCoreLogDocument = new QTextDocument(this);

View File

@ -233,4 +233,5 @@ void MainWindow::UpdateActionTranslations()
// //
action_RCM_CopyGraph->setText(tr("Copy graph as image.")); action_RCM_CopyGraph->setText(tr("Copy graph as image."));
action_RCM_CopyRecentLogs->setText(tr("Copy latest logs.")); action_RCM_CopyRecentLogs->setText(tr("Copy latest logs."));
action_RCM_CopySelected->setText(tr("Copy selected."));
} }

View File

@ -1068,18 +1068,22 @@ This entry is ignored by V2Ray core when using DoH servers.</source>
<source>Copy latest logs.</source> <source>Copy latest logs.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Do you want to remove this group as well?</source> <source>Do you want to remove this group as well?</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Group: </source> <source>Group: </source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Removing Connection</source> <source>Removing Connection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Copy selected.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>OutboundEditor</name> <name>OutboundEditor</name>