Skip to content

Commit

Permalink
ui
Browse files Browse the repository at this point in the history
  • Loading branch information
benapetr committed Jul 18, 2024
1 parent b618d72 commit 2ebbbf6
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/huggle_core/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "exception.hpp"
#include "hooks.hpp"
#include "localization.hpp"
#ifdef QT6_BUILD
#include <QRegularExpression>
#else
#include <QRegEx>
#endif

using namespace Huggle;

Expand Down Expand Up @@ -210,3 +215,15 @@ bool Generic::SecondsToTimeSpan(int time, int *days, int *hours, int *minutes, i
*seconds = remaining_time;
return true;
}

bool Generic::RegexExactMatch(const QString& regex, const QString& input_text)
{
#ifdef QT6_BUILD
QRegularExpression re(regex);
QRegularExpressionMatch match = re.match(input_text);
return match.hasMatch() && (match.captured(0) == input_text);
#else
QRegEx re(regex);
return re.exactMatch(input_text);
#endif
}
2 changes: 2 additions & 0 deletions src/huggle_core/generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace Huggle
* \return new string
*/
HUGGLE_EX_CORE QString ShrinkText(const QString &text, int size, bool html = true, int minimum = 2);

HUGGLE_EX_CORE bool RegexExactMatch(const QString& regex, const QString& input_text);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/huggle_ui/blockuserform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

#include "blockuserform.hpp"
#include <QLineEdit>
#include <QTimer>
#include <QUrl>
#include "ui_blockuserform.h"
#include "blockuserform.hpp"
#include <huggle_core/apiquery.hpp>
#include <huggle_core/apiqueryresult.hpp>
#include <huggle_core/exception.hpp>
Expand All @@ -24,7 +25,6 @@
#include <huggle_core/localization.hpp>
#include <huggle_core/syslog.hpp>
#include <huggle_core/configuration.hpp>
#include "ui_blockuserform.h"
#include "mainwindow.hpp"
#include "history.hpp"
#include "uigeneric.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_ui/blockuserform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#ifndef BLOCKUSER_H
#define BLOCKUSER_H

#include <QString>
#include <huggle_core/definitions.hpp>

#include <QString>
#include <huggle_core/apiquery.hpp>
#include <huggle_core/collectable_smartptr.hpp>
#include "hw.hpp"
Expand All @@ -31,7 +31,7 @@ namespace Huggle
class ApiQuery;

//! This form can be used to block users from editing, which requires the block permission
class BlockUserForm : public HW
class HUGGLE_EX_UI BlockUserForm : public HW
{
Q_OBJECT
public:
Expand Down
2 changes: 1 addition & 1 deletion src/huggle_ui/custommessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

#include "ui_custommessage.h"
#include "custommessage.hpp"
#include <huggle_core/exception.hpp>
#include <huggle_core/wikiuser.hpp>
#include <huggle_core/wikiutil.hpp>
#include <huggle_core/localization.hpp>
#include "ui_custommessage.h"

using namespace Huggle;

Expand Down
3 changes: 2 additions & 1 deletion src/huggle_ui/custommessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define CUSTOMMESSAGE_H

#include <QString>
#include <huggle_core/definitions.hpp>
#include "hw.hpp"

namespace Ui
Expand All @@ -24,7 +25,7 @@ namespace Huggle
class WikiUser;

//! This form can be used to send a custom message to users
class CustomMessage : public HW
class HUGGLE_EX_UI CustomMessage : public HW
{
Q_OBJECT
public:
Expand Down
4 changes: 4 additions & 0 deletions src/huggle_ui/editbaritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ void EditBarItem::SetFrame(Qt::GlobalColor colour)
{
//this->setStyleSheet("QFrame { border-color: " + color + " }");
QPalette px;
#ifdef QT6_BUILD
px.setColor(QPalette::WindowText, colour);
#else
px.setColor(QPalette::Foreground, colour);
#endif
this->setPalette(px);
}

Expand Down
6 changes: 5 additions & 1 deletion src/huggle_ui/hugglelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

#include "ui_hugglelog.h"
#include "hugglelog.hpp"
#include <QDateTime>
#include <QCursor>
Expand All @@ -16,15 +17,18 @@
#include <huggle_core/exception.hpp>
#include <huggle_core/generic.hpp>
#include <huggle_core/syslog.hpp>
#include "ui_hugglelog.h"

using namespace Huggle;

HuggleLog::HuggleLog(QWidget *parent) : QDockWidget(parent), ui(new Ui::HuggleLog)
{
this->ui->setupUi(this);
this->setWindowTitle(_l("logs-widget-name"));
#ifdef QT6_BUILD
this->lock = new HMUTEX_TYPE();
#else
this->lock = new QMutex(QMutex::Recursive);
#endif
this->ui->textEdit->setUndoRedoEnabled(false);
this->ui->textEdit->resize(this->ui->textEdit->width(), 60);
this->Modified = false;
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_ui/hugglelog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <QDockWidget>


class QMutex;
class HMUTEX_TYPE;

namespace Ui
{
Expand All @@ -42,7 +42,7 @@ namespace Huggle
bool Modified;

private:
QMutex *lock;
HMUTEX_TYPE* lock;
QList<HuggleLog_Line> Text;
Ui::HuggleLog *ui;
};
Expand Down
2 changes: 1 addition & 1 deletion src/huggle_ui/hw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#ifndef HW_HPP
#define HW_HPP

#include <huggle_core/definitions.hpp>
#include <QString>
#include <QDialog>
#include <huggle_core/definitions.hpp>

namespace Huggle
{
Expand Down
13 changes: 11 additions & 2 deletions src/huggle_ui/reportuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#include "blockuserform.hpp"
#include "ui_reportuser.h"
#include <QHBoxLayout>
#ifdef QT6_BUILD
#include <QRegularExpression>
#else
#include <QRegExp>
#endif
#include <QSplitter>
#include <QMessageBox>
#include <QModelIndex>
Expand Down Expand Up @@ -594,9 +598,14 @@ void Huggle::ReportUser::on_pushButton_6_clicked()
bool ReportUser::checkUserIsReported()
{
QString regex = this->reportedUser->GetSite()->GetProjectConfig()->ReportUserCheckPattern;
regex.replace("$username", QRegExp::escape(this->reportedUser->Username));
QRegExp pattern(regex);
regex.replace("$username", HREGEX_TYPE::escape(this->reportedUser->Username));
HREGEX_TYPE pattern(regex);
#ifdef QT6_BUILD
QRegularExpressionMatch match = pattern.match(this->reportContent);
return match.hasMatch() && (match.captured(0) == this->reportContent);
#else
return pattern.exactMatch(this->reportContent);
#endif
}

void ReportUser::insertUser()
Expand Down
3 changes: 1 addition & 2 deletions src/huggle_ui/requestprotect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ void RequestProtect::Tick()
// make a regex out of the pattern string
QString regex_str = this->page->GetSite()->GetProjectConfig()->RFPP_Regex;
regex_str.replace("$title", this->page->PageName);
QRegExp rx(regex_str);
if (rx.exactMatch(PageText))
if (Generic::RegexExactMatch(regex_str, PageText))
{
this->Fail(_l("reqprotection-duplicate"));
return;
Expand Down
1 change: 0 additions & 1 deletion src/huggle_ui/requestprotect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <QTimer>
#include "hw.hpp"
#include <QRegExp>
#include <huggle_core/wikipage.hpp>
#include <huggle_core/apiquery.hpp>
#include <huggle_core/editquery.hpp>
Expand Down
4 changes: 3 additions & 1 deletion src/huggle_ui/updateform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,9 @@ static HUGGLE_LPCSTR QString2Msdn(QString text)
#ifdef UNICODE
wchar_t *temp = (wchar_t*)calloc(text.length() + 1, sizeof(wchar_t));
text.toWCharArray(temp);
return _wcsdup(_T(temp));
wchar_t* result = _wcsdup(temp); // Duplicate the wchar_t array
free(temp); // Free the initially allocated memory
return result;
#else
QByteArray byte_array = text.toLocal8Bit();
return _strdup(byte_array.constData());
Expand Down
2 changes: 1 addition & 1 deletion src/huggle_ui/whitelistform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void WhitelistForm::OnTick()
while (this->Whitelist.count() > 0 && i < 200)
{
QString xx = this->Whitelist.at(0);
xx = xx.replace(QRegExp("[^\\w\\s]"), "");
xx = xx.replace(HREGEX_TYPE("[^\\w\\s]"), "");
this->ui->listWidget->addItem(xx);
this->Whitelist.removeAt(0);
i++;
Expand Down

0 comments on commit 2ebbbf6

Please sign in to comment.