Skip to content

Commit ef03f99

Browse files
committed
generic code cleanup
* Implemented function to reset network manager We don't use it (yet) but this could be used to tackle some problems with expired tokens and failed attempts to relogin. Problem is that right now we have single network manager for entire Huggle and share it for all wikis. This needs to change so that we can actually take advantage of such reset, or else we would need to logout from all projects, which isn't efficient. * Moved some inline definition out to .cpp, there is no point in that being inline, it's barely used * Used AI copilot to rename many UI elements that didn't have meaningful name
1 parent 518e2f4 commit ef03f99

21 files changed

+99
-62
lines changed

src/huggle_core/core.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ void Core::ExtensionLoad()
259259
if (!interface)
260260
{
261261
Huggle::Syslog::HuggleLogs->Log("Unable to cast the library to extension: " + ename);
262-
}
263-
else if (interface->CompiledFor() != QString(HUGGLE_VERSION))
262+
} else if (interface->CompiledFor() != QString(HUGGLE_VERSION))
264263
{
265264
Huggle::Syslog::HuggleLogs->WarningLog("Extension " + ename + " was compiled for huggle " + interface->CompiledFor() + " which is not compatible, unloading");
266265
delete interface;
@@ -466,3 +465,18 @@ void Core::HandleException(Exception *exception)
466465
{
467466
Core::HuggleCore->exceptionHandler->HandleException(exception);
468467
}
468+
469+
void Core::ResetNetworkManager()
470+
{
471+
QNetworkAccessManager *old = Query::NetworkManager;
472+
Query::NetworkManager = new QNetworkAccessManager();
473+
Query::NetworkManager->setCookieJar(new QNetworkCookieJar(Query::NetworkManager));
474+
foreach (iExtension *extension, this->Extensions)
475+
{
476+
if (extension->RequestNetwork())
477+
{
478+
extension->Networking = Query::NetworkManager;
479+
}
480+
}
481+
old->deleteLater();
482+
}

src/huggle_core/core.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ namespace Huggle
9090
void Init();
9191
//! Load extensions (libraries as well as python)
9292
void ExtensionLoad();
93+
//! Reinitializes shared instance of network manager, useful to clear stale session data
94+
void ResetNetworkManager();
9395
//! Terminate the process, call this after you release all resources and finish all queries
9496
void Shutdown();
9597
void TestLanguages();

src/huggle_core/projectconfiguration.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,17 @@ QDateTime ProjectConfiguration::ServerTime()
917917
return QDateTime::currentDateTime().addSecs(this->ServerOffset);
918918
}
919919

920+
void ProjectConfiguration::RequestLogin()
921+
{
922+
if (this->IsLoggedIn && !this->RequestingLogin)
923+
{
924+
this->IsLoggedIn = false;
925+
this->Token_Csrf = "";
926+
this->Token_Rollback = "";
927+
this->Token_Watch = "";
928+
}
929+
}
930+
920931
ScoreWord::ScoreWord(QString Word, int Score)
921932
{
922933
this->score = Score;

src/huggle_core/projectconfiguration.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,6 @@ namespace Huggle
323323
QString configurationBuffer;
324324
YAML::Node *yaml_node = nullptr;
325325
};
326-
327-
inline void ProjectConfiguration::RequestLogin()
328-
{
329-
if (this->IsLoggedIn && !this->RequestingLogin)
330-
{
331-
this->IsLoggedIn = false;
332-
this->Token_Csrf = "";
333-
this->Token_Rollback = "";
334-
this->Token_Watch = "";
335-
}
336-
}
337326
}
338327

339328
#endif // PROJECTCONFIGURATION_H

src/huggle_ui/custommessage.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ void CustomMessage::SetWikiUser(WikiUser *User)
4848
this->ui->plainTextEdit->setPlainText(QString(_l("custommessage-wikiuser-plaintext-1", this->user->Username) + "\n\n" + _l("custommessage-wikiuser-plaintext-2") + "\n\n~~~~"));
4949
}
5050

51-
void CustomMessage::on_pushButton_2_clicked()
51+
void CustomMessage::on_cancelButton_clicked()
5252
{
53-
this->hide();
53+
this->close();
5454
}
5555

56-
void CustomMessage::on_pushButton_clicked()
56+
void CustomMessage::on_sendButton_clicked()
5757
{
5858
// plainTextEdit: wikitext message ; lineEdit: section title
5959
WikiUtil::MessageUser(this->user, this->ui->plainTextEdit->toPlainText(), this->ui->lineEdit->text(), this->ui->leSummary->text());
@@ -64,11 +64,11 @@ bool CustomMessage::VerifyMessage()
6464
{
6565
if (this->ui->plainTextEdit->toPlainText().isEmpty() || this->ui->lineEdit->text().isEmpty() || this->ui->leSummary->text().isEmpty())
6666
{
67-
this->ui->pushButton->setEnabled(false);
67+
this->ui->sendButton->setEnabled(false);
6868
return false;
6969
} else
7070
{
71-
this->ui->pushButton->setEnabled(true);
71+
this->ui->sendButton->setEnabled(true);
7272
return true;
7373
}
7474
}

src/huggle_ui/custommessage.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace Huggle
3333
~CustomMessage() override;
3434

3535
private slots:
36-
void on_pushButton_clicked();
37-
void on_pushButton_2_clicked();
36+
void on_sendButton_clicked();
37+
void on_cancelButton_clicked();
3838
bool VerifyMessage();
3939
void on_lineEdit_textChanged();
4040
void on_plainTextEdit_textChanged();

src/huggle_ui/custommessage.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
<item>
6060
<layout class="QHBoxLayout" name="horizontalLayout">
6161
<item>
62-
<widget class="QPushButton" name="pushButton_2">
62+
<widget class="QPushButton" name="cancelButton">
6363
<property name="text">
6464
<string>Cancel</string>
6565
</property>
6666
</widget>
6767
</item>
6868
<item>
69-
<widget class="QPushButton" name="pushButton">
69+
<widget class="QPushButton" name="sendButton">
7070
<property name="text">
7171
<string>Send message</string>
7272
</property>

src/huggle_ui/deleteform.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void DeleteForm::processFailure(QString Reason)
108108
this->ui->pushButton->setEnabled(true);
109109
}
110110

111-
void DeleteForm::on_pushButton_clicked()
111+
void DeleteForm::on_deleteButton_clicked()
112112
{
113113
if (this->ui->checkBox_2->isChecked())
114114
{
@@ -120,21 +120,21 @@ void DeleteForm::on_pushButton_clicked()
120120
}
121121
this->ui->checkBox_2->setEnabled(false);
122122
this->ui->comboBox->setEnabled(false);
123-
this->ui->pushButton->setEnabled(false);
123+
this->ui->deleteButton->setEnabled(false);
124124
// let's delete the page
125125
this->qDelete = new ApiQuery(ActionDelete, this->page->GetSite());
126126
this->qDelete->Parameters = "title=" + QUrl::toPercentEncoding(this->page->PageName)
127127
+ "&reason=" + QUrl::toPercentEncoding(Configuration::GenerateSuffix(this->ui->comboBox->lineEdit()->text(),
128128
this->page->GetSite()->GetProjectConfig()))
129129
+ "&token=" + QUrl::toPercentEncoding(this->page->GetSite()->GetProjectConfig()->Token_Csrf);
130-
this->qDelete->Target = "Deleting " + this->page->PageName;
130+
this->qDelete->Target = "Deleting " + this->page->PageName;
131131
this->qDelete->UsingPOST = true;
132132
QueryPool::HugglePool->AppendQuery(this->qDelete);
133133
this->qDelete->Process();
134134

135-
if (this->associatedTalkPage != nullptr)
135+
if (this->ui->checkBox_2->isChecked() && this->associatedTalkPage != nullptr)
136136
{
137-
// let's delete the talk page
137+
// we also want to delete the talk page
138138
this->qTalk = new ApiQuery(ActionDelete, this->page->GetSite());
139139
this->qTalk->Parameters = "title=" + QUrl::toPercentEncoding(this->associatedTalkPage->PageName)
140140
+ "&reason=" + QUrl::toPercentEncoding(Configuration::GenerateSuffix(Configuration::HuggleConfiguration->ProjectConfig->AssociatedDelete,
@@ -145,12 +145,14 @@ void DeleteForm::on_pushButton_clicked()
145145
QueryPool::HugglePool->AppendQuery(this->qTalk);
146146
this->qTalk->Process();
147147
}
148-
this->tDelete = new QTimer();
148+
149+
// we need to wait for the deletion to finish before we can close the form
150+
this->tDelete = new QTimer(this);
149151
connect(this->tDelete, SIGNAL(timeout()), this, SLOT(OnTick()));
150152
this->tDelete->start(HUGGLE_TIMER);
151153
}
152154

153-
void DeleteForm::on_pushButton_2_clicked()
155+
void DeleteForm::on_cancelButton_clicked()
154156
{
155157
this->close();
156158
}

src/huggle_ui/deleteform.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ namespace Huggle
4444
*/
4545
void SetPage(WikiPage *Page, WikiUser *User);
4646
private slots:
47-
void on_pushButton_clicked();
48-
void on_pushButton_2_clicked();
4947
void OnTick();
48+
void on_deleteButton_clicked();
49+
void on_cancelButton_clicked();
5050
private:
5151
void deletePage();
5252
void processFailure(QString Reason);

src/huggle_ui/deleteform.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
<item>
5252
<layout class="QHBoxLayout" name="horizontalLayout">
5353
<item>
54-
<widget class="QPushButton" name="pushButton_2">
54+
<widget class="QPushButton" name="cancelButton">
5555
<property name="text">
5656
<string>Cancel</string>
5757
</property>
5858
</widget>
5959
</item>
6060
<item>
61-
<widget class="QPushButton" name="pushButton">
61+
<widget class="QPushButton" name="deleteButton">
6262
<property name="mouseTracking">
6363
<bool>false</bool>
6464
</property>

0 commit comments

Comments
 (0)