Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "default_host" profile #2950

Merged
merged 14 commits into from Aug 15, 2019
52 changes: 26 additions & 26 deletions src/Host.cpp
Expand Up @@ -1692,44 +1692,44 @@ void Host::setUserDictionaryOptions(const bool _useDictionary, const bool useSha
{
Q_UNUSED(_useDictionary);
bool useDictionary = true;
QMutexLocker locker(& mLock);
bool isChanged = false;
QMutexLocker locker(&mLock);
bool dictionaryChanged {};
Copy link
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
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
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:

// Copy the value while we have the lock:
bool isSpellCheckingEnabled = mEnableSpellCheck;
if (mEnableUserDictionary != useDictionary) {
mEnableUserDictionary = useDictionary;
isChanged = true;
dictionaryChanged = true;
}

if (mUseSharedDictionary != useShared) {
mUseSharedDictionary = useShared;
isChanged = true;
dictionaryChanged = true;
}
locker.unlock();

// During start-up this gets called for the default_host profile - but that
// has a null mpConsole:
if (mpConsole) {
if (isChanged) {
// This will propogate the changes in the two flags to the main
// TConsole's copies of them - although setProfileSpellDictionary() is
// also called in the main TConsole constructor:
mpConsole->setProfileSpellDictionary();
}
if (!mpConsole) {
return;
}

// This also needs to handle the spell checking against the system/mudlet
// bundled dictionary being switched on or off. Given that if it has
// been disabled the spell checking code won't run we need to clear any
// highlights in the TCommandLine instance that may have been present when
// spell checking is turned on or off:
if (isSpellCheckingEnabled) {
// Now enabled - so recheck the whole command line with whichever
// dictionaries are active:
mpConsole->mpCommandLine->recheckWholeLine();
} else {
// Or it is now disabled so clear any spelling marks:
mpConsole->mpCommandLine->clearMarksOnWholeLine();
}
if (dictionaryChanged) {
// This will propogate the changes in the two flags to the main
// TConsole's copies of them - although setProfileSpellDictionary() is
// also called in the main TConsole constructor:
mpConsole->setProfileSpellDictionary();
}

// This also needs to handle the spell checking against the system/mudlet
// bundled dictionary being switched on or off. Given that if it has
// been disabled the spell checking code won't run we need to clear any
// highlights in the TCommandLine instance that may have been present when
// spell checking is turned on or off:
if (isSpellCheckingEnabled) {
// Now enabled - so recheck the whole command line with whichever
// dictionaries are active:
mpConsole->mpCommandLine->recheckWholeLine();
} else {
// Or it is now disabled so clear any spelling marks:
mpConsole->mpCommandLine->clearMarksOnWholeLine();
}
}

Expand Down
56 changes: 27 additions & 29 deletions src/TConsole.cpp
Expand Up @@ -757,38 +757,36 @@ void TConsole::closeEvent(QCloseEvent* event)
}
}

if (mProfileName != QLatin1String("default_host")) {
TEvent conCloseEvent {};
conCloseEvent.mArgumentList.append(QLatin1String("sysExitEvent"));
conCloseEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mpHost->raiseEvent(conCloseEvent);

if (mpHost->mFORCE_SAVE_ON_EXIT) {
mudlet::self()->saveWindowLayout();
mpHost->modulesToWrite.clear();
mpHost->saveProfile();

if (mpHost->mpMap->mpRoomDB->size() > 0) {
QDir dir_map;
QString directory_map = mudlet::getMudletPath(mudlet::profileMapsPath, mProfileName);
// CHECKME: Consider changing datetime spec to more "sortable" "yyyy-MM-dd#HH-mm-ss" (3 of 6)
QString filename_map = mudlet::getMudletPath(mudlet::profileDateTimeStampedMapPathFileName, mProfileName, QDateTime::currentDateTime().toString("dd-MM-yyyy#hh-mm-ss"));
if (!dir_map.exists(directory_map)) {
dir_map.mkpath(directory_map);
}
QFile file_map(filename_map);
if (file_map.open(QIODevice::WriteOnly)) {
QDataStream out(&file_map);
mpHost->mpMap->serialize(out);
file_map.close();
}
TEvent conCloseEvent{};
conCloseEvent.mArgumentList.append(QStringLiteral("sysExitEvent"));
conCloseEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mpHost->raiseEvent(conCloseEvent);

if (mpHost->mFORCE_SAVE_ON_EXIT) {
mudlet::self()->saveWindowLayout();
mpHost->modulesToWrite.clear();
mpHost->saveProfile();

if (mpHost->mpMap->mpRoomDB->size() > 0) {
QDir dir_map;
QString directory_map = mudlet::getMudletPath(mudlet::profileMapsPath, mProfileName);
// CHECKME: Consider changing datetime spec to more "sortable" "yyyy-MM-dd#HH-mm-ss" (3 of 6)
QString filename_map = mudlet::getMudletPath(mudlet::profileDateTimeStampedMapPathFileName, mProfileName, QDateTime::currentDateTime().toString("dd-MM-yyyy#hh-mm-ss"));
if (!dir_map.exists(directory_map)) {
dir_map.mkpath(directory_map);
}
QFile file_map(filename_map);
if (file_map.open(QIODevice::WriteOnly)) {
QDataStream out(&file_map);
mpHost->mpMap->serialize(out);
file_map.close();
}
event->accept();
return;
}
event->accept();
return;
}

if (mProfileName != "default_host" && !mUserAgreedToCloseConsole) {
if (!mUserAgreedToCloseConsole) {
ASK:
int choice = QMessageBox::question(this, tr("Save profile?"), tr("Do you want to save the profile %1?").arg(mProfileName), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (choice == QMessageBox::Cancel) {
Expand All @@ -809,7 +807,7 @@ void TConsole::closeEvent(QCloseEvent* event)
QDir dir_map;
QString directory_map = mudlet::getMudletPath(mudlet::profileMapsPath, mProfileName);
// CHECKME: Consider changing datetime spec to more "sortable" "yyyy-MM-dd#HH-mm-ss" (4 of 6)
QString filename_map = mudlet::getMudletPath(mudlet::profileDateTimeStampedMapPathFileName, mProfileName, QDateTime::currentDateTime().toString("dd-MM-yyyy#hh-mm-ss"));
QString filename_map = mudlet::getMudletPath(mudlet::profileDateTimeStampedMapPathFileName, mProfileName, QDateTime::currentDateTime().toString(QStringLiteral("dd-MM-yyyy#hh-mm-ss")));
if (!dir_map.exists(directory_map)) {
dir_map.mkpath(directory_map);
}
Expand Down
55 changes: 24 additions & 31 deletions src/dlgConnectionProfiles.cpp
Expand Up @@ -1189,8 +1189,7 @@ void dlgConnectionProfiles::fillout_form() {
mProfileList = QDir(mudlet::getMudletPath(mudlet::profilesPath)).entryList(QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Name);

// if only the default_host is present it means no profiles have yet been created
if (mProfileList.isEmpty() || (mProfileList.size() == 1 && mProfileList.at(0) == QStringLiteral("default_host"))) {
if (mProfileList.isEmpty()) {
welcome_message->show();
requiredArea->hide();
informationalArea->hide();
Expand Down Expand Up @@ -1604,13 +1603,7 @@ void dlgConnectionProfiles::fillout_form() {
#if defined(QT_DEBUG)
mudServer = QStringLiteral("Mudlet self-test");
if (!deletedDefaultMuds.contains(mudServer) && !mProfileList.contains(mudServer)) {
for (int i = mProfileList.size() - 1; i >= 0; --i) {
if (mProfileList.at(i) == QLatin1String("default_host")) {
mProfileList.insert(i, mudServer);
break;
}
}

mProfileList.append(mudServer);
pM = new QListWidgetItem(mudServer);
pM->setFont(font);
pM->setForeground(QColor(Qt::white));
Expand All @@ -1628,36 +1621,36 @@ void dlgConnectionProfiles::fillout_form() {
QString toselectProfileName;
int toselectRow = -1;
int test_profile_row = -1;
bool firstMudletLaunch = true;

for (int i = 0; i < profiles_tree_widget->count(); i++) {
auto profile = profiles_tree_widget->item(i);
auto profileName = profile->text();
const auto profile = profiles_tree_widget->item(i);
const auto profileName = profile->text();
if (profileName == QStringLiteral("Mudlet self-test")) {
test_profile_row = i;
}

QDateTime profile_lastRead = QFileInfo(
mudlet::getMudletPath(mudlet::profileXmlFilesPath, profileName)).lastModified();
// Since Qt 5.x null QTimes and QDateTimes are invalid - and might not
// work as expected - so test for validity of the test_date value as well
if ((!test_date.isValid()) || profile_lastRead > test_date) {
test_date = profile_lastRead;
toselectProfileName = profileName;
toselectRow = i;
const auto fileinfo = QFileInfo(
mudlet::getMudletPath(mudlet::profileXmlFilesPath, profileName));

if (fileinfo.exists()) {
firstMudletLaunch = false;
QDateTime profile_lastRead = fileinfo.lastModified();
// Since Qt 5.x null QTimes and QDateTimes are invalid - and might not
// work as expected - so test for validity of the test_date value as well
if ((!test_date.isValid()) || profile_lastRead > test_date) {
test_date = profile_lastRead;
toselectProfileName = profileName;
toselectRow = i;
}
}
}

if (toselectRow != -1 && toselectProfileName == QStringLiteral("default_host") &&
profiles_tree_widget->count() > 1) {
// if the last profile read is default_host, it means the user hasn't created
// any profiles yet since default_host profile cannot actually be used. In this case,
// select a random pre-defined profile to give all MUDs a fair go

// make sure not to select the default_host or test_profile though
auto default_host_row = toselectRow;
// dont infinite loop.
if (test_profile_row == -1 || profiles_tree_widget->count() != 2) {
while (toselectRow == default_host_row || toselectRow == test_profile_row) {
if (firstMudletLaunch) {
// Select a random pre-defined profile to give all MUDs a fair go first time
// make sure not to select the test_profile though
if (profiles_tree_widget->count() != 1) {
while (toselectRow == -1 || toselectRow == test_profile_row) {
toselectRow = qrand() % profiles_tree_widget->count();
}
}
Expand Down Expand Up @@ -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
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
Member Author

Choose a reason for hiding this comment

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

Fixed.

if (hostManager.addHost(profile_name, port_entry->text().trimmed(), QString(), QString())) {
if (mudlet::self()->addHost(profile_name, port_entry->text().trimmed(), QString(), QString())) {
pHost = hostManager.getHost(profile_name);
if (!pHost) {
return;
Expand Down
21 changes: 8 additions & 13 deletions src/dlgProfilePreferences.cpp
Expand Up @@ -724,10 +724,10 @@ void dlgProfilePreferences::initWithHost(Host* pHost)
mpMenu->clear();
for (unsigned int i = 0, total = profileList.size(); i < total; ++i) {
QString s = profileList.at(i);
if (s.isEmpty() || !s.compare(pHost->getName()) || !s.compare(QStringLiteral("default_host"))) {
if (s.isEmpty() || !s.compare(pHost->getName())) {
// Do not include THIS profile in the list - it will
// automatically get saved - as the file to copy to the other
// profiles! Also exclude the dummy "default_host" one
// profiles!
continue;
}

Expand Down Expand Up @@ -1081,9 +1081,7 @@ void dlgProfilePreferences::clearHostDetails()
acceptServerGUI->setChecked(false);

// Given that the IRC sub-system can handle there NOT being an active host
// this may need revising - but then the IRC sub-system may need to be fixed
// to handle switching back to the "default_host" should the currently
// active one be the one "going away" at this point...
// this may need revising
ircHostName->clear();
ircHostPort->clear();
ircChannels->clear();
Expand Down Expand Up @@ -2911,21 +2909,18 @@ void dlgProfilePreferences::slot_changeShowLineFeedsAndParagraphs(const bool sta

/*
* This is to deal particularly with the case where the preferences dialog is
* opened without a host instance (other than the dummy "default_host") being
* around - and then the user starts up a profile and one gets created.
* In that situation we detect the signal that the mudlet class sends out (now)
* opened without a host instance being around - and then the user starts up
* a profile and one gets created.
* In that situation we detect the signal that the mudlet class sends out
* when a host is created and wire it up into the controls that until then
* have been disabled/greyed-out.
*/
void dlgProfilePreferences::slot_handleHostAddition(Host* pHost, const quint8 count)
{
// 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 < 2) {
// We have not been constructed with a valid Host pointer,
// AND a real Host instance has just been created
// AND there are only two Host instances (the "real" one and the
// "default_host") around.
// AND there is only one Host instance around.
mpHost = pHost;
// So make connections to the details of the real Host instance:
initWithHost(pHost);
Expand Down