refactor: Qt, GTK, web client UI consistency

This commit is contained in:
Charles Kerr 2022-02-20 13:33:53 -06:00
parent 581c3f9854
commit 8d5c900ee0
9 changed files with 125 additions and 73 deletions

View File

@ -2241,28 +2241,9 @@ namespace
std::string get_editable_tracker_list(tr_torrent const* tor)
{
std::ostringstream gstr;
int tier = 0;
for (size_t i = 0, n = tr_torrentTrackerCount(tor); i < n; ++i)
{
auto const tracker = tr_torrentTracker(tor, i);
if (tier != tracker.tier)
{
tier = tracker.tier;
gstr << '\n';
}
gstr << tracker.announce << '\n';
}
auto str = gstr.str();
if (!str.empty())
{
str.resize(str.size() - 1);
}
char* cstr = tr_torrentGetTrackerList(tor);
auto str = std::string{ cstr != nullptr ? cstr : "" };
tr_free(cstr);
return str;
}
@ -2291,8 +2272,8 @@ void DetailsDialog::Impl::on_edit_trackers()
auto* l = Gtk::make_managed<Gtk::Label>();
l->set_markup(
_("To add a backup URL, add it on the line after the primary URL.\n"
"To add another primary URL, add it after a blank line."));
_("To add a backup URL, add it on the next line after a primary URL.\n"
"To add a new primary URL, add it after a blank line."));
l->set_justify(Gtk::JUSTIFY_LEFT);
l->set_halign(Gtk::ALIGN_START);
l->set_valign(Gtk::ALIGN_CENTER);
@ -2309,6 +2290,13 @@ void DetailsDialog::Impl::on_edit_trackers()
fr->set_size_request(500U, 166U);
t->add_wide_tall_control(row, *fr);
l = Gtk::make_managed<Gtk::Label>();
l->set_markup(_("Also see Default Public Trackers in Edit > Preferences > Network"));
l->set_justify(Gtk::JUSTIFY_LEFT);
l->set_halign(Gtk::ALIGN_START);
l->set_valign(Gtk::ALIGN_CENTER);
t->add_wide_control(row, *l);
gtr_dialog_set_content(*d, *t);
d->set_data(TORRENT_ID_KEY, GINT_TO_POINTER(torrent_id));

View File

@ -176,13 +176,6 @@ Gtk::Entry* new_entry(tr_quark const key, Glib::RefPtr<Session> const& core)
return w;
}
void text_buffer_changed_cb(Glib::RefPtr<Gtk::TextBuffer> buffer, tr_quark const key, Glib::RefPtr<Session> const& core)
{
Gtk::TextBuffer::iterator start, end;
buffer->get_bounds(start, end);
core->set_pref(key, buffer->get_text(start, end, FALSE));
}
Gtk::Widget* new_text_view(tr_quark const key, Glib::RefPtr<Session> const& core)
{
auto* w = Gtk::make_managed<Gtk::TextView>();
@ -195,10 +188,16 @@ Gtk::Widget* new_text_view(tr_quark const key, Glib::RefPtr<Session> const& core
scroll->set_policy(Gtk::PolicyType::POLICY_AUTOMATIC, Gtk::PolicyType::POLICY_AUTOMATIC);
scroll->set_shadow_type(Gtk::ShadowType::SHADOW_IN);
scroll->add(*w);
scroll->set_size_request(-1, 200);
scroll->set_size_request(-1, 166);
/* signal */
buffer->signal_changed().connect([buffer, key, core]() { text_buffer_changed_cb(buffer, key, core); });
w->add_events(Gdk::FOCUS_CHANGE_MASK);
w->signal_focus_out_event().connect(
[buffer, key, core](GdkEventFocus*)
{
core->set_pref(key, buffer->get_text());
return false;
});
return scroll;
}
@ -1078,9 +1077,14 @@ Gtk::Widget* PrefsDialog::Impl::networkPage()
w->set_tooltip_text(_("LPD is a tool for finding peers on your local network."));
t->add_wide_control(row, *w);
t->add_section_title(row, _("Default Trackers"));
t->add_section_divider(row);
t->add_section_title(row, _("Default Public Trackers"));
auto tv = new_text_view(TR_KEY_default_trackers, core_);
tv->set_tooltip_text(_("Trackers for public torrents to use automatically"));
tv->set_tooltip_text(
_("Trackers to use on all public torrents.\n\n"
"To add a backup URL, add it on the next line after a primary URL.\n"
"To add a new primary URL, add it after a blank line."));
t->add_wide_control(row, *tv);
return t;

View File

@ -1189,7 +1189,13 @@ char* tr_torrentGetMagnetLink(tr_torrent const* tor);
/**
* Returns a newly-allocated string listing its tracker's announce URLs.
* One URL per line, with a blank line between tiers
* One URL per line, with a blank line between tiers.
*
* NOTE: this only includes the trackers included in the torrent and,
* along with tr_torrentSetTrackerList(), is intended for import/export
* and user editing. It does *not* include the "default trackers" that
* are applied to all public torrents. If you want a full display of all
* trackers, use tr_torrentTracker() and tr_torrentTackerCount()
*/
char* tr_torrentGetTrackerList(tr_torrent const* tor);
@ -1415,6 +1421,13 @@ struct tr_tracker_view
struct tr_tracker_view tr_torrentTracker(tr_torrent const* torrent, size_t i);
/**
* Count all the trackers (both active and backup) this torrent is using.
*
* NOTE: this is for a status display only and may include trackers from
* the default tracker list if this is a public torrent. If you want a
* list of trackers the user can edit, see tr_torrentGetTrackerList().
*/
size_t tr_torrentTrackerCount(tr_torrent const* torrent);
/*

View File

@ -240,10 +240,9 @@ void PrefsDialog::linkWidgetToPref(QWidget* widget, int pref_key)
return;
}
auto const* plain_text_edit = qobject_cast<QPlainTextEdit*>(widget);
if (plain_text_edit != nullptr)
if (auto const* edit = qobject_cast<QPlainTextEdit*>(widget); edit != nullptr)
{
connect(plain_text_edit, &QPlainTextEdit::textChanged, this, &PrefsDialog::plainTextChanged);
connect(edit, &QPlainTextEdit::textChanged, this, &PrefsDialog::plainTextChanged);
return;
}
}

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>601</width>
<height>597</height>
<height>657</height>
</rect>
</property>
<property name="windowTitle">
@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabs">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<property name="elideMode">
<enum>Qt::ElideNone</enum>
@ -983,18 +983,50 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="defaultTrackersLabel">
<property name="toolTip">
<string>a list of default trackers to be added to new public torrents (and existing ones, after a reload)</string>
</property>
<property name="text">
<string>Default Trackers:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="defaultTrackersSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="defaultTrackersLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Default Public Trackers</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="defaultTrackersLayout">
<property name="leftMargin">
<number>18</number>
</property>
<item>
<widget class="QPlainTextEdit" name="defaultTrackersPlainTextEdit">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Trackers to use on all public torrents.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;To add a backup URL, add it on the next line after a primary URL.&lt;/p&gt;&lt;p&gt;To add a new primary URL, add it after a blank line.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<width>515</width>
<height>450</height>
</rect>
</property>
@ -33,19 +33,30 @@
<number>18</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="primaryLabel">
<property name="text">
<string>To add another primary URL, add it after a blank line.</string>
<string>To add a new primary URL, add it after a blank line.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPlainTextEdit" name="trackerList"/>
<widget class="QPlainTextEdit" name="trackerList">
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="destinationLabel">
<widget class="QLabel" name="backupLabel">
<property name="text">
<string>To add a backup URL, add it on the line after the primary URL.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;To add a backup URL, add it on the next line after a primary URL.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="defaultsLabel">
<property name="text">
<string>Also see Default Public Trackers in Edit &gt; Preferences &gt; Network</string>
</property>
</widget>
</item>

File diff suppressed because one or more lines are too long

View File

@ -122,15 +122,6 @@ export class PrefsDialog extends EventTarget {
const n = Formatter.number(value);
element.innerHTML = `Blocklist has <span class="blocklist-size-number">${n}</span> rules`;
setTextContent(this.elements.peers.blocklist_update_button, 'Update');
} else if (element.tagName === 'TEXTAREA') {
if (
// eslint-disable-next-line eqeqeq
element.value != value &&
element !== document.activeElement
) {
element.value = value;
element.dispatchEvent(new Event('change'));
}
} else {
switch (element.type) {
case 'checkbox':
@ -141,6 +132,7 @@ export class PrefsDialog extends EventTarget {
}
break;
case 'text':
case 'textarea':
case 'url':
case 'email':
case 'number':
@ -163,6 +155,7 @@ export class PrefsDialog extends EventTarget {
}
break;
default:
console.log(element.type);
break;
}
}
@ -660,19 +653,26 @@ export class PrefsDialog extends EventTarget {
const utp_check = cal.check;
label = document.createElement('div');
label.textContent = 'Default trackers';
label.textContent = 'Default Public Trackers';
label.classList.add('section-label');
root.append(label);
label = document.createElement('label');
label.textContent =
'(added to new public torrents and to existing ones on reload):';
root.append(label);
const tracker_labels = [
'Trackers to use on all public torrents.',
'To add a backup URL, add it on the next line after a primary URL.',
'To add a new primary URL, add it after a blank line.',
];
for (const text of tracker_labels) {
label = document.createElement('label');
label.classList.add('default-trackers-label');
label.textContent = text;
label.setAttribute('for', 'default-trackers');
root.append(label);
}
const textarea = document.createElement('textarea');
textarea.dataset.key = 'default-trackers';
textarea.id = 'default-trackers';
label.setAttribute('for', textarea.id);
root.append(textarea);
const default_trackers_textarea = textarea;

View File

@ -791,6 +791,11 @@ $popup-top: 61px; // TODO: ugly that this is hardcoded
}
}
#default-trackers,
.default-trackers-label {
grid-column: 1 / 3;
}
.alt-speed-label {
font-size: smaller;
font-style: lighter;