improve server list: now all rows enabled, but mark red for incompatible and ignore it selection
pult improved for roles menu
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
#include <piqt.h>
|
||||
#include "ccm_SHS_shared.h"
|
||||
|
||||
const char property_alive[] = "SHS_is_alive";
|
||||
const char property_alive [] = "SHS_is_alive";
|
||||
const char property_address[] = "SHS_address";
|
||||
const int role_server_info = Qt::UserRole;
|
||||
const int role_compatible = Qt::UserRole + 1;
|
||||
REGISTER_VARIANT(ServerAddress);
|
||||
|
||||
|
||||
@@ -23,6 +25,12 @@ enum Column {
|
||||
cIP,
|
||||
cVersions,
|
||||
};
|
||||
enum Icon {
|
||||
iIncompatible,
|
||||
iOff,
|
||||
iOnline,
|
||||
iOnlineEmpty,
|
||||
};
|
||||
|
||||
|
||||
SHServersTreeWidget::SHServersTreeWidget(QWidget * parent): QWidget(parent) {
|
||||
@@ -38,9 +46,10 @@ SHServersTreeWidget::SHServersTreeWidget(QWidget * parent): QWidget(parent) {
|
||||
connect(ui->tree, &QTreeWidget::itemClicked, this, [this](){on_tree_doubleClicked(QModelIndex());});
|
||||
#endif
|
||||
popup_menu.addAction(ui->actionRemove);
|
||||
icon_state[0] = QIcon(":/icons/status-off.png");
|
||||
icon_state[1] = QIcon(":/icons/status-green.png");
|
||||
icon_state[2] = QIcon(":/icons/status-on.png");
|
||||
icon_state[iIncompatible] = QIcon(":/icons/led_off.png");
|
||||
icon_state[iOff] = QIcon(":/icons/status-off.png");
|
||||
icon_state[iOnline] = QIcon(":/icons/status-green.png");
|
||||
icon_state[iOnlineEmpty] = QIcon(":/icons/status-on.png");
|
||||
bc_channel = new SHClientChannel();
|
||||
bc_channel->setID(generateID());
|
||||
CONNECTU_QUEUED(bc_channel, broadcastReceiveEvent, this, broadcastReceiveEvent, this);
|
||||
@@ -65,6 +74,7 @@ void SHServersTreeWidget::setPultView() {
|
||||
|
||||
|
||||
void SHServersTreeWidget::selectCurrentServer() {
|
||||
if (!currentCompatible()) return;
|
||||
auto si = currentServer();
|
||||
if (!si.isValid()) return;
|
||||
emit serverSelected(si);
|
||||
@@ -154,15 +164,15 @@ void SHServersTreeWidget::fill() {
|
||||
PIMutexLocker _ml(smutex);
|
||||
for (const PacketServerInfo & i: servers_) {
|
||||
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
||||
ti->setData(cServer, Qt::UserRole, QVariant::fromValue(i));
|
||||
ti->setIcon(cServer, icon_state[0]);
|
||||
ti->setData(cServer, role_server_info, QVariant::fromValue(i));
|
||||
ti->setData(cServer, role_compatible, i.compatible());
|
||||
ti->setIcon(cServer, icon_state.value(iIncompatible));
|
||||
ti->setText(cServer, PI2QString(i.name));
|
||||
ti->setText(cHostname, PI2QString(i.identify.hostname));
|
||||
ti->setText(cOS, QString("%1 (%2)").arg(ose.valueToKey(i.identify.os_type)).arg(PI2QString(i.identify.os_version)));
|
||||
ti->setText(cChannel, cte.valueToKey(i.channel));
|
||||
ti->setText(cIP, PI2QString(i.address.ipAddress()));
|
||||
ti->setText(cVersions, PI2QString(i.displayVersion()));
|
||||
ti->setDisabled(!i.compatible());
|
||||
ui->tree->addTopLevelItem(ti);
|
||||
}
|
||||
setIcons();
|
||||
@@ -174,18 +184,21 @@ void SHServersTreeWidget::fill() {
|
||||
|
||||
void SHServersTreeWidget::setIcons() {
|
||||
for (int i = 0; i < ui->tree->topLevelItemCount(); ++i) {
|
||||
auto si = ui->tree->topLevelItem(i)->data(cServer, Qt::UserRole).value<PacketServerInfo>();
|
||||
bool is_alive = false;
|
||||
int icon = 0;
|
||||
auto si = ui->tree->topLevelItem(i)->data(cServer, role_server_info).value<PacketServerInfo>();
|
||||
auto * ch = channels.value(si.address.hash(), nullptr);
|
||||
if (ch) {
|
||||
is_alive = ch->property(property_alive).toBool();
|
||||
if (is_alive) {
|
||||
if (si.name.isEmpty()) icon = 2;
|
||||
else icon = 1;
|
||||
bool is_compat = ui->tree->topLevelItem(i)->data(cServer, role_compatible).toBool();
|
||||
bool is_alive = false;
|
||||
if (ch) is_alive = ch->property(property_alive).toBool();
|
||||
int icon = iOff;
|
||||
if (is_alive) {
|
||||
if (!is_compat)
|
||||
icon = iIncompatible;
|
||||
else {
|
||||
if (si.name.isEmpty()) icon = iOnlineEmpty;
|
||||
else icon = iOnline;
|
||||
}
|
||||
}
|
||||
ui->tree->topLevelItem(i)->setIcon(cServer, icon_state[icon]);
|
||||
ui->tree->topLevelItem(i)->setIcon(cServer, icon_state.value(icon));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +211,8 @@ void SHServersTreeWidget::on_tree_customContextMenuRequested(const QPoint & pos)
|
||||
|
||||
|
||||
void SHServersTreeWidget::on_tree_doubleClicked(QModelIndex) {
|
||||
PacketServerInfo info = currentServer();
|
||||
if (!currentCompatible()) return;
|
||||
auto info = currentServer();
|
||||
if (!info.isValid() || info.connect_address.isEmpty()) return;
|
||||
emit serverSelected(info);
|
||||
}
|
||||
@@ -231,7 +245,7 @@ void SHServersTreeWidget::on_buttonUpdate_clicked() {
|
||||
void SHServersTreeWidget::on_actionRemove_triggered() {
|
||||
auto * ti = ui->tree->currentItem();
|
||||
if (!ti) return;
|
||||
auto si = ti->data(cServer, Qt::UserRole).value<PacketServerInfo>();
|
||||
auto si = ti->data(cServer, role_server_info).value<PacketServerInfo>();
|
||||
uint addr_hash = si.address.hash();
|
||||
auto * ch = channels.value(addr_hash, nullptr);
|
||||
if (ch) {
|
||||
@@ -362,7 +376,16 @@ PacketServerInfo SHServersTreeWidget::currentServer() const {
|
||||
QTreeWidgetItem * ci = ui->tree->currentItem();
|
||||
if (!ci)
|
||||
return PacketServerInfo();
|
||||
return ci->data(cServer, Qt::UserRole).value<PacketServerInfo>();
|
||||
return ci->data(cServer, role_server_info).value<PacketServerInfo>();
|
||||
}
|
||||
|
||||
|
||||
bool SHServersTreeWidget::currentCompatible() const {
|
||||
QTreeWidgetItem * ci = ui->tree->currentItem();
|
||||
if (!ci)
|
||||
return false;
|
||||
return ci->data(cServer, role_compatible).toBool();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
|
||||
PIVector<PacketServerInfo> servers() const;
|
||||
PacketServerInfo currentServer() const;
|
||||
bool currentCompatible() const;
|
||||
|
||||
private:
|
||||
bool event(QEvent * e) override;
|
||||
@@ -53,7 +54,7 @@ private:
|
||||
PIMap<uint, SHClientChannel * > channels;
|
||||
SHClientChannel * bc_channel;
|
||||
SHClientChannel * channel = nullptr;
|
||||
QIcon icon_state[3];
|
||||
QMap<int, QIcon> icon_state;
|
||||
QMenu popup_menu;
|
||||
mutable PIMutex smutex;
|
||||
int timer_pip;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<file>../../icons/status-on.png</file>
|
||||
<file>../../icons/status-green.png</file>
|
||||
<file>../../icons/status-off.png</file>
|
||||
<file>../../icons/led_off.png</file>
|
||||
<file>../../icons/view-refresh.png</file>
|
||||
<file>../../../AUTHORS.txt</file>
|
||||
</qresource>
|
||||
|
||||
@@ -308,7 +308,7 @@ void RemoteClient::receiveEvent(PIByteArray data) {
|
||||
if (hdr.type < 0) return;
|
||||
PIByteArray ba;
|
||||
PIString str;
|
||||
qDebug() << "packet type" << hdr.type;
|
||||
//qDebug() << "packet type" << hdr.type;
|
||||
switch ((SHNetworkTypes::PacketType)hdr.type) {
|
||||
case SHNetworkTypes::KeyProbeResult:
|
||||
data >> kres;
|
||||
@@ -484,9 +484,12 @@ void RemoteClient::appStateChanged(Qt::ApplicationState state) {
|
||||
void RemoteClient::changeRoleRequest(int index) {
|
||||
ServerUserRole role;
|
||||
role.index = index;
|
||||
bool ok = false;
|
||||
QString password = QInputDialog::getText(nullptr, tr("SHS Pult"), tr("Input password:"), QLineEdit::Password, "", &ok);
|
||||
if (!ok) return;
|
||||
QString password;
|
||||
if (role.index > 0) {
|
||||
bool ok = false;
|
||||
password = QInputDialog::getText(nullptr, tr("SHS Pult"), tr("Input password:"), QLineEdit::Password, "", &ok);
|
||||
if (!ok) return;
|
||||
}
|
||||
role.password_hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Sha256);
|
||||
PIByteArray ba = SHNetworkTypes::makeHeader(SHNetworkTypes::ChangeUserRole);
|
||||
ba << role;
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#include "SH_ui_loader.h"
|
||||
#include "SH_base.h"
|
||||
#include "pultwindow_desktop.h"
|
||||
#include "pultwindow_android.h"
|
||||
#include "client.h"
|
||||
#include "client_messages.h"
|
||||
#ifdef ANDROID
|
||||
# include "pultwindow_android.h"
|
||||
# include "android.h"
|
||||
# include <QAndroidService>
|
||||
# include <QAndroidJniObject>
|
||||
|
||||
@@ -44,7 +44,11 @@ PultWindowAndroid::PultWindowAndroid(QWidget * parent): PultWindowBase(parent) {
|
||||
b->setIcon(a->icon());
|
||||
b->setText(a->text());
|
||||
b->setProperty("_action", qulonglong(a));
|
||||
connect(b, SIGNAL(clicked(bool)), a, SLOT(trigger()));
|
||||
if (a->menu()) {
|
||||
b->setMenu(a->menu());
|
||||
} else {
|
||||
connect(b, SIGNAL(clicked(bool)), a, SLOT(trigger()));
|
||||
}
|
||||
side->layout()->addWidget(b);
|
||||
buttons_list << b;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ PultWindowBase::PultWindowBase(QWidget * parent): QWidget(parent) {
|
||||
sep->setSeparator(true);
|
||||
pult_menu->addAction(sep);
|
||||
pult_menu->addAction(QIcon(":/icons/application-exit.png"), tr("Exit"), this, SLOT(exitTriggered()));
|
||||
role_menu->menuAction()->setVisible(false);
|
||||
#ifndef MOBILE_VIEW
|
||||
tray.setContextMenu(pult_menu);
|
||||
tray.setIcon(QIcon(":/icons/SH_pult_remote.png"));
|
||||
@@ -301,10 +302,12 @@ void PultWindowBase::connected(PacketServerInfo server) {
|
||||
if (r.privilege == 0) a->setChecked(true);
|
||||
connect(a, &QAction::triggered, this, [this, a, r](){
|
||||
emit changeRoleRequest(r.index);
|
||||
emit hideMenuRequest();
|
||||
a->setChecked(user_role == a->data().toInt());
|
||||
});
|
||||
role_menu->addAction(a);
|
||||
}
|
||||
role_menu->menuAction()->setVisible(server.user_roles.size_s() > 1);
|
||||
setStatusText(tr("Check key ..."));
|
||||
}
|
||||
|
||||
@@ -316,6 +319,7 @@ void PultWindowBase::fetching() {
|
||||
|
||||
void PultWindowBase::disconnected() {
|
||||
qDeleteAll(role_menu->actions());
|
||||
role_menu->menuAction()->setVisible(false);
|
||||
user_role = 0;
|
||||
//piCout << "PultWindowBase::disconnected";
|
||||
downloading = false;
|
||||
|
||||
@@ -446,7 +446,7 @@ void ServerCore::timerEvent(QTimerEvent * e) {
|
||||
PIByteArray diff;
|
||||
if (r->role_changed) {
|
||||
diff = Q2PIByteArray(sync.buildTransitionDiff(r->user_role, r->new_user_role));
|
||||
qDebug() << "send transitionsl diff" << r->user_role << "->" << r->new_user_role << diff.size();
|
||||
//qDebug() << "send transitional diff" << r->user_role << "->" << r->new_user_role << diff.size();
|
||||
r->newRoleDone();
|
||||
if (!diff.isEmpty()) {
|
||||
diff.insert(0, SHNetworkTypes::makeHeader(SHNetworkTypes::GuiSyncDiff));
|
||||
|
||||
Reference in New Issue
Block a user