Skip to content

Remove "default_host" profile#2950

Merged
vadi2 merged 14 commits intoMudlet:developmentfrom
vadi2:remove-default-host
Aug 15, 2019
Merged

Remove "default_host" profile#2950
vadi2 merged 14 commits intoMudlet:developmentfrom
vadi2:remove-default-host

Conversation

@vadi2
Copy link
Copy Markdown
Member

@vadi2 vadi2 commented Aug 7, 2019

Brief overview of PR changes/additions

Remove "default_host" profile.

Motivation for adding to Mudlet

200ms faster startup because of no extra host getting made + 10ms saved from creating the debug area only when you need it, less messy code workarounds to ignore the "default_host" and no messages like this in stdout which don't mean anything:

cTelnet::~cTelnet() Instance being destroyed before it could display some messages,
messages are:
------------
[  OK  ]  - Lua module rex_pcre loaded.
------------
[  OK  ]  - Lua module zip loaded.
------------
[  OK  ]  - Lua module lfs loaded.
------------
[  OK  ]  - Lua module sqlite3 loaded.
------------
[  OK  ]  - Lua module utf8 loaded.
------------
[  OK  ]  - Lua module yajl loaded.
------------
[ INFO ]  - Map audit starting...
------------
[  OK  ]  - Auditing of map completed (0.00s). Enjoy your game...
------------
[  OK  ]  - Map loaded successfully (0s).
------------

Other info (issues closed, discussion etc)

Opening IRC is now not possible until at least one profile open - but I don't think anyone seriously uses Mudlet as an IRC-only client. We previously kept this functionality was the only way to get help, but with Discord, this isn't needed.

Closes #1352, closes #1351, closes #736.

@vadi2 vadi2 added this to the 4.1.0 milestone Aug 7, 2019
@vadi2 vadi2 requested review from SlySven and itsTheFae August 7, 2019 19:21
@vadi2 vadi2 requested a review from a team as a code owner August 7, 2019 19:21
@vadi2 vadi2 requested a review from a team August 7, 2019 19:21
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Aug 7, 2019

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

// count will be 2 in the case we particularly want to handle (adding the
// first real Host instance):
if (!mpHost && pHost && count < 3) {
if (!mpHost && pHost && count < 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were <3 before, you remove default_host, now it should be <2, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

QMutexLocker locker(& mLock);
bool isChanged = false;
QMutexLocker locker(&mLock);
bool dictionaryChanged {};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never seen this syntax before

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've used it in a few places in Mudlet now. It creates dictionaryChanged and sets it to a default value you'd expect. If you just do bool dictionaryChanged; the value could be random because one wasn't given (it basically doesn't do anything at all to set one).

Technical term is "braced intializer", unfortunately all resources I could find from a quick search weren't an easy read.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses the default constructor IIRC - in the same manner as it would be for a member in a class's constructor's initialization list, e.g. if dictionaryChanged was a member then this would do the same as:

, dictionaryChanged()

would do in the initialization list.

Arguments can also be provided for the constructor of more complex items - and even bools can be initialized to the non-default value true with:

bool dictionaryChanged {true};

:neckbeard:

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Aug 8, 2019

@wiploo are you able to test if this breaks anything? It is a pretty fundamental change.

src/mudlet.cpp Outdated

bool mudlet::addHost(const QString& hostname, const QString& port, const QString& login, const QString& pass)
{
auto success = mHostManager.addHost(hostname, port, login, pass);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have HostManager::addHost() and mudlet::addHost() and the intention is that it's only the latter that should be called, because it wraps some necessary initialisation (the central debug area) around the method once we have our first host.

I'm not sure how to properly describe it using C++ semantics.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make only the latter callable?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mudlet class is overriding the addHost method of the HostManager class maybe? 🤓

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, this design was bad. Fixed it to a more logical one - you call HostManager.addHost as you did before now.

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Aug 8, 2019

We previously kept this functionality was the only way to get help, but with Discord, this isn't needed.

Not everyone has/uses/can use (Chinese users?) Discord.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Aug 8, 2019

That is true, and they have their own QQ group, so IRC is not relevant to them.

src/mudlet.cpp Outdated
||(mMenuBarVisibility & visibleMaskNormally)) {

// Are there any profiles loaded?
if ((mHostManager.getHostCount() < 1 && mMenuBarVisibility & visibleAlways)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The < 1 is redundant... 😉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, fixed.

src/mudlet.cpp Outdated
// as the first one
if ((mHostManager.getHostCount() < 2 && mToolbarVisibility & visibleAlways) || (mToolbarVisibility & visibleMaskNormally)) {
// Are there any profiles loaded?
if ((mHostManager.getHostCount() < 1 && mToolbarVisibility & visibleAlways)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, so below...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

src/mudlet.cpp Outdated

if (success && !mpDebugArea) {
mpDebugArea = new QMainWindow(nullptr);
mpDefaultHost = mHostManager.getHost(hostname);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Um, Huston, we may have a problem - it looks like this and the next line will make the Central Debug Console belong to the first profile open - so what happens to the CDC when multi-playing and the first profile is closed - does that make the CDC die as well...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, yes, you raise a valid point. I'll have it migrate to the next available profile (if any) then.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, tough. We could just also close the debug area and re-open it with the next available host, but then the user experience is not so nice: everything that was in the debug area will get lost. On the other hand, implementing host migration for an existing TConsole is a fair bit of work just for this one usecase.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be a Host pointer - or is it only for the QObject::parent property so that if the parent is destroyed it causes all the QObject derived children of that parent to commit suicide? If that is the case then perhaps the CDC can be given the mudlet singleton as a parent - then things ought to be fine.

I haven't got the code open in front of me right now (😮) but I will take a look over the weekend if I can make sense of this...

On the other hand, implementing host migration for an existing TConsole is a fair bit of work just for this one usecase.

That one TConsole instance is an important use case - and we (I certainly) have suggested to users to have the debug console opened from a dummy profile before the one with a start-up problem is initiated - so that early debug output can be observed in the latter - so it is important that the CDC is shared equally between all open profiles. {Fair enough there is also a long-standing need for a means to show which profile produces which lines in the CDC!}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does need a valid Host, yeah.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -3685,7 +3690,7 @@ void mudlet::doAutoLogin(const QString& profile_name)

// load an old profile if there is any
// PLACEMARKER: Host creation (2) - autoload case
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revise the number down now that // PLACEMARKER: Host creation (1) ... has gone away.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see the point of these placemakers. Revised, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were/are marking all the places where a profile/Host can be created (and there are some for destruction) - which is useful to check that all of them are passed through/tested in some situations (as we have had cases where one execution path showed a bug that another one didn't) and putting breakpoints on them is one technique I have used to debug things in those cases.

Copy link
Copy Markdown
Member Author

@vadi2 vadi2 Aug 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modern IDEs have a "find all usages of this function" feature which does the same, but better: it never forgets to update comments 😁

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just like the Qt TODO plugin as it makes it very quick and simple to jump to previously commented/marked places in the whole project...

Screenshot_20190812_164548

Screenshot_20190812_164718

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but, doing these things requires manual work to keep it up to date - which can be wrong! So it has a low reliability score - thus I'd ignore it and only trust the source...

@@ -2028,7 +2021,7 @@ void dlgConnectionProfiles::loadProfile(bool alsoConnect)
}
// load an old profile if there is any
// PLACEMARKER: Host creation (3) - normal case
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revise the number down now that // PLACEMARKER: Host creation (1) ... has gone away.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

src/mudlet.cpp Outdated

// For the first real host created the getHostCount() will return 2 because
// there is already a "default_host"
signal_hostCreated(pHost, mHostManager.getHostCount());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you haven't already done so, may I suggest checking any slots connected to this signal to ensure that they respond correctly given that the number passed will be one less now...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the only place it is used in is the settings window, and that works OK.

Also, this is a strange way to emit a signal...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Humm, yeah - where has the emit gone?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was like that from the beginning 92f61bb#diff-84e2883dc57a4e7b034fbac3fd4668b5R2633 - I'll fix it.

src/mudlet.cpp Outdated

bool mudlet::addHost(const QString& hostname, const QString& port, const QString& login, const QString& pass)
{
auto success = mHostManager.addHost(hostname, port, login, pass);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mudlet class is overriding the addHost method of the HostManager class maybe? 🤓

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Aug 10, 2019

Ready for review.

mpMainToolBar->actions()[14]->setEnabled(false);

mpActionReplay->setEnabled(false);
mpActionIRC->setEnabled(false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best place for this line of code - IMHO it would be better placed before or after the pair of lines it is sat between which both act on mpActionReplay rather than splitting them...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, applied.

Copy link
Copy Markdown
Member

@demonnic demonnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launches, deleted default_host, still launches, test profile isn't erroring. Does load faster.

@vadi2 vadi2 merged commit 6b29b60 into Mudlet:development Aug 15, 2019
@vadi2 vadi2 deleted the remove-default-host branch August 15, 2019 16:43
SlySven added a commit to SlySven/Mudlet that referenced this pull request Sep 23, 2021
It seems, *I think* that the removal of the "default host" profile (in
Mudlet#2950) broke the logic that detected that any "real" profiles were loaded
and prevented both the main menu bar and the main toolbar from being hidden
when no such profiles were active. As it is now it is not possible to hide
both the main menu and the main toolbar AFTER a profile is loaded - even
though we provide the settings that are suppose to allow that.

The original `enum` used to encode the wanted settings for the visibility
of those two items used a cunning combination of bit patterns (and some
application of DeMorgan's laws) to work out what the visibility settings
are and what state the application is in (number of profiles active) so as
to show or hide the main menu and main toolbars. Unfortunately I've lost
track of how I put it together when the single "default host" profile
was included in the count so had to rewrite the logic tests without
changing the `enum` values.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
SlySven added a commit that referenced this pull request Sep 25, 2021
It seems, *I think* that the removal of the "default host" profile (in
#2950) broke the logic that detected that any "real" profiles were loaded
and prevented both the main menu bar and the main toolbar from being hidden
when no such profiles were active. As it is now it is not possible to hide
both the main menu and the main toolbar AFTER a profile is loaded - even
though we provide the settings that are suppose to allow that.

The original `enum` used to encode the wanted settings for the visibility
of those two items used a cunning combination of bit patterns (and some
application of DeMorgan's laws) to work out what the visibility settings
are and what state the application is in (number of profiles active) so as
to show or hide the main menu and main toolbars. Unfortunately I've lost
track of how I put it together when the single "default host" profile
was included in the count so had to rewrite the logic tests without
changing the `enum` values.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants