From b919a64ae6ce24f87ec1155dcae8833b12ca2f53 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Wed, 31 May 2023 22:22:23 +0200 Subject: [PATCH] move to QString --- include/champcache.h | 6 +- include/clientaccess.h | 12 ++-- include/clientapi.h | 62 +++++++++++--------- include/config.h | 6 +- include/datadragon.h | 38 ++++++------- include/datadragonimagecache.h | 16 +++--- include/files.h | 7 ++- include/json.h | 2 +- include/lolautoaccept.h | 8 +-- include/memoryimagecache.h | 10 ++-- include/position.h | 9 +-- include/restclient.h | 14 ++--- include/runeaspekt.h | 10 ++-- include/runedisplay.h | 4 +- include/runepage.h | 2 + include/runestyle.h | 6 +- include/settingstab.h | 2 +- include/stagesettings.h | 8 +-- src/blitzapi.cpp | 18 +++--- src/champcache.cpp | 18 +++--- src/championsearch.cpp | 6 +- src/champrow.cpp | 6 +- src/clientaccess.cpp | 38 ++++++------- src/clientaccess_linux.cpp | 60 +++++++++----------- src/clientaccess_windows.cpp | 28 ++++----- src/clientapi.cpp | 80 +++++++++++++------------- src/clientapi_json.cpp | 87 +++++++++++++++------------- src/config.cpp | 22 ++++---- src/datadragon.cpp | 100 ++++++++++++++++----------------- src/datadragonimagecache.cpp | 16 +++--- src/files.cpp | 38 +++++-------- src/lolautoaccept.cpp | 100 ++++++++++++++++----------------- src/mainwindow.cpp | 8 +-- src/memoryimagecache.cpp | 6 +- src/restclient.cpp | 32 +++++------ src/runedisplay.cpp | 19 ++++--- src/runeeditor.cpp | 12 ++-- src/runemanager.cpp | 2 +- src/runepage.cpp | 4 ++ src/runepagelist.cpp | 8 +-- src/settingstab.cpp | 6 +- src/stagesettings.cpp | 14 ++--- 42 files changed, 476 insertions(+), 474 deletions(-) diff --git a/include/champcache.h b/include/champcache.h index ba78115..61fad14 100644 --- a/include/champcache.h +++ b/include/champcache.h @@ -8,12 +8,12 @@ class ChampCache { public: ChampCache(); - std::string getVersion(); + QString getVersion(); QJsonDocument getChamps(); - void saveChamps(QJsonDocument doc, const std::string& version); + void saveChamps(QJsonDocument doc, const QString& version); private: - std::string basefolder; + QString basefolder; uint64_t maxage = 86400; // is in seconds }; \ No newline at end of file diff --git a/include/clientaccess.h b/include/clientaccess.h index 20c942a..b21001a 100644 --- a/include/clientaccess.h +++ b/include/clientaccess.h @@ -1,25 +1,25 @@ #pragma once #include -#include #include -#include + +#include class ClientAccess { ClientAccess(); public: - ClientAccess(const std::string& token, uint16_t port); + ClientAccess(const QString& token, uint16_t port); static std::shared_ptr find(); public: - std::string getBasicAuth() const; + QString getBasicAuth() const; uint16_t getPort() const; - std::string getURL() const; + QString getURL() const; private: - std::string authcode; + QString authcode; uint16_t port = 0; }; diff --git a/include/clientapi.h b/include/clientapi.h index 5288170..3365351 100644 --- a/include/clientapi.h +++ b/include/clientapi.h @@ -37,7 +37,7 @@ public: ENDOFGAME, TERMINATEDINERROR, }; - static GameflowPhase toGameflowPhase(const std::string&); + static GameflowPhase toGameflowPhase(const QString&); enum class ChampSelectPhase : uint32_t { INVALID = 0, @@ -46,7 +46,7 @@ public: BAN_PICK, FINALIZATION }; - static ChampSelectPhase toChampSelectPhase(const std::string& str); + static ChampSelectPhase toChampSelectPhase(const QString& str); enum class ChampSelectActionType : uint32_t { INVALID = 0, @@ -54,7 +54,7 @@ public: PICK, TEN_BANS_REVEAL, }; - static ChampSelectActionType toChampSelectActionType(const std::string& str); + static ChampSelectActionType toChampSelectActionType(const QString& str); struct TimerInfo { int64_t adjustedTimeLeftInPhase = 0; @@ -71,12 +71,12 @@ public: struct PlayerInfo { int64_t summonerid = 0; // to test validity -> test if this is not null - std::string gameName; - std::string name; - std::string statusMessage; + QString gameName; + QString name; + QString statusMessage; // lol specific - std::string puuid; + QString puuid; uint32_t level = 0; }; @@ -139,7 +139,7 @@ public: struct RunePage { uint64_t id = 0; uint64_t lastmodified = 0; - std::string name; + QString name; bool isDeleteable = true; bool isEditable = true; bool isActive = false; // what is the difference between active and current???? @@ -153,30 +153,30 @@ public: }; struct Message { - std::string body; - std::string fromId; - std::string fromPid; + QString body; + QString fromId; + QString fromPid; int64_t fromSummonerId; - std::string id; + QString id; bool isHistorical; - std::string timestamp; - std::string type; // known types: chat (1:1), customGame, championSelect, groupchat + QString timestamp; + QString type; // known types: chat (1:1), customGame, championSelect, groupchat Message(); explicit Message(const QJsonObject& json); }; struct Conversation { - std::string gameName; - std::string gameTag; - std::string id; + QString gameName; + QString gameTag; + QString id; bool isMuted; std::shared_ptr lastMessage; - std::string name; - std::string password; - std::string pid; - std::string targetRegion; - std::string type; + QString name; + QString password; + QString pid; + QString targetRegion; + QString type; int64_t unreadMessageCount; Conversation(); @@ -201,7 +201,7 @@ public: // chats std::vector getAllConversations(); - Message sendMessage(const std::string& chatid, const std::string& messagebody); + Message sendMessage(const QString& chatid, const QString& messagebody); // rune stuff RunePage getCurrentRunePage(); @@ -214,7 +214,7 @@ public: std::vector getAllRuneAspekts(); std::vector getAllRuneStyles(); - const std::string& getRuneStyleByID(uint32_t id); + const QString& getRuneStyleByID(uint32_t id); QPixmap getImageResource(QString path); @@ -225,7 +225,13 @@ private: DataDragonImageCache imageCache; }; -std::ostream& operator<<(std::ostream&, const ClientAPI::ReadyCheckState&); -std::ostream& operator<<(std::ostream&, const ClientAPI::GameflowPhase&); -std::ostream& operator<<(std::ostream&, const ClientAPI::ChampSelectPhase&); -std::ostream& operator<<(std::ostream&, const ClientAPI::ChampSelectActionType&); +#define DEFINEOPERATOR(CLASS) \ + std::ostream& operator<<(std::ostream&, const ClientAPI::CLASS&); \ + QDebug operator<<(QDebug, const ClientAPI::CLASS&); + +DEFINEOPERATOR(ReadyCheckState); +DEFINEOPERATOR(GameflowPhase); +DEFINEOPERATOR(ChampSelectPhase); +DEFINEOPERATOR(ChampSelectActionType); + +#undef DEFINEOPERATOR diff --git a/include/config.h b/include/config.h index 9c82a33..a76e5d6 100644 --- a/include/config.h +++ b/include/config.h @@ -13,7 +13,7 @@ public: StageConfig(const QJsonObject&); operator QJsonObject() const; - std::vector champs; + std::vector champs; bool enabled = false; }; @@ -71,7 +71,7 @@ public: RootConfig& getConfig(); private: - std::string configFolderPath; - std::string configFilePath; + QString configFolderPath; + QString configFilePath; RootConfig root; }; diff --git a/include/datadragon.h b/include/datadragon.h index 6aec402..eda7b33 100644 --- a/include/datadragon.h +++ b/include/datadragon.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -19,7 +19,7 @@ class DataDragon : public RestClient { public: using notifyImgfunc_t = std::function; - DataDragon(const std::string& locale); + DataDragon(const QString& locale); ~DataDragon(); DataDragon(const DataDragon&) = delete; DataDragon& operator=(const DataDragon&) = delete; @@ -29,11 +29,11 @@ public: ChampData(); ChampData(const QJsonObject& source); - std::string name; - std::string id; + QString name; + QString id; int key = 0; - std::string partype; - std::string title; + QString partype; + QString title; }; enum class ImageType { @@ -43,25 +43,25 @@ public: }; // might block until version is available - const std::string& getVersion(); + const QString& getVersion(); // might block until champ data is available const std::vector& getChamps(); // might block until image is downloaded - QPixmap getImage(const std::string& champid, ImageType imgtype = ImageType::SQUARE, bool writeMemcache = true); - void getImageAsnyc(const std::string& champid, notifyImgfunc_t func, ImageType imgtype = ImageType::SQUARE); + QPixmap getImage(const QString& champid, ImageType imgtype = ImageType::SQUARE, bool writeMemcache = true); + void getImageAsnyc(const QString& champid, notifyImgfunc_t func, ImageType imgtype = ImageType::SQUARE); // might block until champ data is available - const ChampData& getBestMatchingChamp(const std::string& name, int* count = nullptr); - std::vector getMatchingChamp(const std::string& name, uint32_t limit = 25); + const ChampData& getBestMatchingChamp(const QString& name, int* count = nullptr); + std::vector getMatchingChamp(const QString& name, uint32_t limit = 25); const ChampData* getChampByID(uint32_t id); - std::vector resolveChampIDs(const std::vector& champnames); + std::vector resolveChampIDs(const std::vector& champnames); static const ChampData EMPTYCHAMP; protected: - std::string getImageUrl(const std::string& champid, ImageType type); - std::string getCDNString() const; + QString getImageUrl(const QString& champid, ImageType type); + QString getCDNString() const; - void prefetchChampImage(const std::string& champid, ImageType imgtype = ImageType::SQUARE); + void prefetchChampImage(const QString& champid, ImageType imgtype = ImageType::SQUARE); void getVersionInternal(); void getChampsInternal(); void startThread(); @@ -69,16 +69,16 @@ protected: void stopAndJoinThread(); void threadLoop(); - std::string locale; - std::string version; + QString locale; + QString version; std::vector champs; std::mutex cachedatamutex; std::condition_variable cachedatacv; - std::set notDownloadedImages; // the champions of which the square image is not downloaded yet. Is used to download them on idle + std::set notDownloadedImages; // the champions of which the square image is not downloaded yet. Is used to download them on idle private: struct Task { - std::string champid; + QString champid; notifyImgfunc_t func; ImageType type; }; diff --git a/include/datadragonimagecache.h b/include/datadragonimagecache.h index fc25f28..52ef185 100644 --- a/include/datadragonimagecache.h +++ b/include/datadragonimagecache.h @@ -1,20 +1,20 @@ #pragma once -#include +#include #include #include class DataDragonImageCache { public: - DataDragonImageCache(const std::string& folderextra, const std::string& imageext = ".jpg"); + DataDragonImageCache(const QString& folderextra, const QString& imageext = ".jpg"); ~DataDragonImageCache(); - bool hasImage(const std::string& name); - QPixmap getImage(const std::string& name); - void addImageRaw(const QByteArray& arr, const std::string& name); + bool hasImage(const QString& name); + QPixmap getImage(const QString& name); + void addImageRaw(const QByteArray& arr, const QString& name); private: - std::string getFilepath(const std::string& name) const; + QString getFilepath(const QString& name) const; - std::string cacheDir; - std::string imageext; // file extention including dot + QString cacheDir; + QString imageext; // file extention including dot }; diff --git a/include/files.h b/include/files.h index c9b3998..13c90ee 100644 --- a/include/files.h +++ b/include/files.h @@ -3,12 +3,13 @@ // stuff required for file handling #include +#include // create a directory and its parents -bool mkdirs(const std::string& path); +bool mkdirs(const QString& path); // get $HOME or a useful default value -std::string getHome(); +QString getHome(); // folder for caching example: $HOME/.cache/lolautoaccept/ -std::string getCache(); +QString getCache(); diff --git a/include/json.h b/include/json.h index 544d1fd..6dfb428 100644 --- a/include/json.h +++ b/include/json.h @@ -22,7 +22,7 @@ template<> uint64_t convert(const QJsonValue& val); template<> -std::string convert(const QJsonValue& val); +QString convert(const QJsonValue& val); template<> bool convert(const QJsonValue& val); diff --git a/include/lolautoaccept.h b/include/lolautoaccept.h index 4a4dcb6..955bc9d 100644 --- a/include/lolautoaccept.h +++ b/include/lolautoaccept.h @@ -51,9 +51,9 @@ protected: bool smiteWarnEnabled = true; bool autoWriteTextEnabled = false; bool autoWriteTextDone = false; - std::string autoWriteText; + QString autoWriteText; - std::string chatid; // the chatid of the chat from the champselect + QString chatid; // the chatid of the chat from the champselect std::chrono::time_point lastMessageSent; public: @@ -88,7 +88,7 @@ public: const std::vector& getRuneStyles(); void applyRunes(); void setOnRuneChangeFunc(onruneschange_func on); - void setAutoWriteText(bool enabled, const std::string& text = {}); + void setAutoWriteText(bool enabled, const QString& text = {}); signals: void statusChanged(LolAutoAccept::Status); // new status: 0 = off, 1 = on, 2 = failed @@ -118,7 +118,7 @@ private: static int32_t getMatchingRunePage(const RunePage& rp, const std::vector& allpages); void champSelect(); void smiteWarning(const std::vector& cells); - const std::string& getChatid(); + const QString& getChatid(); void applyRunes_internal(uint32_t champid, Position pos); }; diff --git a/include/memoryimagecache.h b/include/memoryimagecache.h index e3c2351..bb5b3c5 100644 --- a/include/memoryimagecache.h +++ b/include/memoryimagecache.h @@ -1,27 +1,27 @@ #pragma once #include -#include +#include #include class MemoryImageCache { public: MemoryImageCache(size_t maxsize = 25); - void addImage(QPixmap, const std::string& title, int type); - QPixmap getImage(const std::string& title, int type); + void addImage(QPixmap, const QString& title, int type); + QPixmap getImage(const QString& title, int type); private: void cleanUp(); struct CachedImage { time_t lastaccessed = 0; QPixmap imageref; - std::string title; + QString title; int type; bool operator<(const CachedImage& other) const; }; - static std::function getImageMatcher(const std::string& title, int type); + static std::function getImageMatcher(const QString& title, int type); std::list cache; size_t maxsize; diff --git a/include/position.h b/include/position.h index c5b3e35..491324e 100644 --- a/include/position.h +++ b/include/position.h @@ -1,8 +1,8 @@ #pragma once +#include #include - enum class Position : uint32_t { INVALID = 0, TOP, @@ -11,10 +11,11 @@ enum class Position : uint32_t { BOTTOM, UTILITY }; -Position toPosition(const std::string& str); -std::string toString(Position p); -std::string toShortString(Position p); +Position toPosition(const QString& str); +QString toString(Position p); +QString toShortString(Position p); std::ostream& operator<<(std::ostream&, const Position&); +QDebug operator<<(QDebug , const Position&); Q_DECLARE_METATYPE(Position); diff --git a/include/restclient.h b/include/restclient.h index b844a56..4a89f2e 100644 --- a/include/restclient.h +++ b/include/restclient.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -11,7 +11,7 @@ class RestClient { public: - RestClient(const std::string& base); + RestClient(const QString& base); RestClient(const RestClient&) = delete; virtual ~RestClient(); @@ -30,16 +30,16 @@ public: }; protected: - QByteArray requestRaw(const std::string& url, Method m = Method::GET, const std::string& data = {}); - QJsonDocument request(const std::string& url, Method m = Method::GET, const std::string& data = {}); + QByteArray requestRaw(const QString& url, Method m = Method::GET, const QString& data = {}); + QJsonDocument request(const QString& url, Method m = Method::GET, const QString& data = {}); void enableDebugging(bool enabled = true); - std::string escape(const std::string& in) const; + QString escape(const QString& in) const; - std::string baseurl; + QString baseurl; CURL* curl = nullptr; // the curl (does curling) - std::string basicauth; // basic auth code (user:pw) or empty string to disable + QString basicauth; // basic auth code (user:pw) or empty string to disable #ifdef WIN32 bool disableCertCheck = true; #else diff --git a/include/runeaspekt.h b/include/runeaspekt.h index 8afb2a9..b333dc2 100644 --- a/include/runeaspekt.h +++ b/include/runeaspekt.h @@ -7,11 +7,11 @@ class QJsonObject; struct RuneAspekt { uint32_t id = 0; - std::string name; - std::string shortDesc; - std::string longDesc; - std::string tooltip; - std::string iconPath; + QString name; + QString shortDesc; + QString longDesc; + QString tooltip; + QString iconPath; RuneAspekt(); explicit RuneAspekt(const QJsonObject& json); diff --git a/include/runedisplay.h b/include/runedisplay.h index 6c102cb..d8d844d 100644 --- a/include/runedisplay.h +++ b/include/runedisplay.h @@ -29,8 +29,8 @@ signals: private: void updateText(); - std::string getRuneText(uint32_t id); - std::string getRuneStyleByID(uint32_t id); + QString getRuneText(uint32_t id); + QString getRuneStyleByID(uint32_t id); Ui::RuneDisplay *ui; diff --git a/include/runepage.h b/include/runepage.h index e3af151..727a3b0 100644 --- a/include/runepage.h +++ b/include/runepage.h @@ -4,6 +4,7 @@ #include #include +#include #include // represents a runepage struct RunePage { @@ -22,3 +23,4 @@ public: }; std::ostream& operator<<(std::ostream&, const RunePage&); +QDebug operator<<(QDebug, const RunePage&); diff --git a/include/runestyle.h b/include/runestyle.h index 9a77c04..4d93478 100644 --- a/include/runestyle.h +++ b/include/runestyle.h @@ -18,9 +18,9 @@ struct RuneStyleSlot { struct RuneStyle { uint32_t id; - std::string name; - std::string iconPath; - std::string tooltip; + QString name; + QString iconPath; + QString tooltip; std::vector allowedSubStyles; QString idName; diff --git a/include/settingstab.h b/include/settingstab.h index 8d235e6..edde371 100644 --- a/include/settingstab.h +++ b/include/settingstab.h @@ -25,7 +25,7 @@ public: std::vector getChamps(LolAutoAccept::State s) const; bool getState(LolAutoAccept::State s) const; - void setChamps(LolAutoAccept::State s, const std::vector&); + void setChamps(LolAutoAccept::State s, const std::vector&); void setState(LolAutoAccept::State s, bool b); Position getPosition() const; diff --git a/include/stagesettings.h b/include/stagesettings.h index 4b233d1..71792f6 100644 --- a/include/stagesettings.h +++ b/include/stagesettings.h @@ -27,13 +27,13 @@ public: void setState(bool); struct SelectedChamp { - SelectedChamp(std::string name, uint32_t id); - std::string name; + SelectedChamp(QString name, uint32_t id); + QString name; uint32_t id; }; std::vector getChampions() const; - void setChampions(const std::vector& champs); + void setChampions(const std::vector& champs); void setDataDragon(DataDragon* dd); void addChamp(const DataDragon::ChampData& cd, QPixmap icon); @@ -52,7 +52,7 @@ signals: private: // delete all items - void resolveAndAddChamp(const std::string& name, bool emitchange = false); + void resolveAndAddChamp(const QString& name, bool emitchange = false); void clear(); void updateEnabled(); diff --git a/src/blitzapi.cpp b/src/blitzapi.cpp index 0bab554..65c328c 100644 --- a/src/blitzapi.cpp +++ b/src/blitzapi.cpp @@ -12,7 +12,7 @@ // query=query ChampionBuilds($championId:Int!,$queue:Queue!,$role:Role,$opponentChampionId:Int,$key:ChampionBuildKey){championBuildStats(championId:$championId,queue:$queue,role:$role,opponentChampionId:$opponentChampionId,key:$key){championId opponentChampionId queue role builds{completedItems{games index averageIndex itemId wins}games mythicId mythicAverageIndex primaryRune runes{games index runeId wins treeId}skillOrders{games skillOrder wins}startingItems{games startingItemIds wins}summonerSpells{games summonerSpellIds wins}wins}}} // &variables={"championId":25,"role":"SUPPORT","queue":"RANKED_SOLO_5X5","opponentChampionId":null,"key":"PUBLIC"} -static const std::string POSITIONNAMES[] = {"INVALID", "TOP", "JUNGLE", "MIDDLE", "BOTTOM", "SUPPORT"}; +static const QString POSITIONNAMES[] = {"INVALID", "TOP", "JUNGLE", "MIDDLE", "BOTTOM", "SUPPORT"}; BlitzAPI::BlitzAPI() : RestClient("https://league-champion-aggregate.iesdev.com/graphql?") {} @@ -58,7 +58,7 @@ BlitzAPI::ChampionInfo::ChampionInfo(const QJsonObject& json) { auto runeid = rune["runeId"]; if(runeid.isDouble()) { runes.at(index+1) = runeid.toDouble(); - Log::debug << "found rune: index: " << index << " +1 set to: " << runes.at(index+1); + qDebug() << "found rune: index: " << index << " +1 set to: " << runes.at(index+1); if(index == 0) { runepage.primaryStyle = rune["treeId"].toInt(); @@ -80,7 +80,7 @@ BlitzAPI::ChampionInfo BlitzAPI::getChampionInfo(uint32_t championID, Position p vars["championId"] = (int) championID; if(p != Position::INVALID) { - vars["role"] = QString::fromStdString(POSITIONNAMES[(int) p]); + vars["role"] = POSITIONNAMES[(int) p]; } vars["queue"] = "RANKED_SOLO_5X5"; @@ -91,10 +91,10 @@ BlitzAPI::ChampionInfo BlitzAPI::getChampionInfo(uint32_t championID, Position p vars["key"] = "PUBLIC"; // ? what does this do? QJsonDocument jvars(vars); - const std::string variables = jvars.toJson(QJsonDocument::Compact).toStdString(); - const std::string query = "query ChampionBuilds($championId:Int!,$queue:Queue!,$role:Role,$opponentChampionId:Int,$key:ChampionBuildKey){championBuildStats(championId:$championId,queue:$queue,role:$role,opponentChampionId:$opponentChampionId,key:$key){championId opponentChampionId queue role builds{completedItems{games index averageIndex itemId wins}games mythicId mythicAverageIndex primaryRune runes{games index runeId wins treeId}skillOrders{games skillOrder wins}startingItems{games startingItemIds wins}summonerSpells{games summonerSpellIds wins}wins}}}"; - const std::string requeststr = "query=" + escape(query) + "&variables=" + escape(variables); - Log::debug << "GetChampionInfo requestVariables: " << variables << " requeststr: " << requeststr; + const QString variables = jvars.toJson(QJsonDocument::Compact); + const QString query = "query ChampionBuilds($championId:Int!,$queue:Queue!,$role:Role,$opponentChampionId:Int,$key:ChampionBuildKey){championBuildStats(championId:$championId,queue:$queue,role:$role,opponentChampionId:$opponentChampionId,key:$key){championId opponentChampionId queue role builds{completedItems{games index averageIndex itemId wins}games mythicId mythicAverageIndex primaryRune runes{games index runeId wins treeId}skillOrders{games skillOrder wins}startingItems{games startingItemIds wins}summonerSpells{games summonerSpellIds wins}wins}}}"; + const QString requeststr = "query=" + escape(query) + "&variables=" + escape(variables); + qDebug() << "GetChampionInfo requestVariables: " << variables << " requeststr: " << requeststr; QJsonDocument doc; try { @@ -105,11 +105,11 @@ BlitzAPI::ChampionInfo BlitzAPI::getChampionInfo(uint32_t championID, Position p if(!doc.isObject()) { // error - Log::error << "could not get ChampionInfo. Returned Response: " << doc.toJson().toStdString(); + qCritical() << "could not get ChampionInfo. Returned Response: " << doc.toJson(); return {}; } - Log::debug << "championinfo Response: " << doc.toJson().trimmed().toStdString(); + qDebug() << "championinfo Response: " << doc.toJson().trimmed(); QJsonObject obj = doc.object(); QJsonValueRef dataref = obj["data"]; diff --git a/src/champcache.cpp b/src/champcache.cpp index f41b87a..e36c7f3 100644 --- a/src/champcache.cpp +++ b/src/champcache.cpp @@ -18,17 +18,17 @@ static qint64 ageOfFile(QFile& f) { return info.lastModified().secsTo(QDateTime::currentDateTime()); } -std::string ChampCache::getVersion() { - QFile versionfile(QString::fromStdString(basefolder + "version")); +QString ChampCache::getVersion() { + QFile versionfile(basefolder + "version"); if(ageOfFile(versionfile) < (qint64) maxage) { versionfile.open(QFile::ReadOnly); - return versionfile.readAll().toStdString(); + return versionfile.readAll(); } return {}; // empty string } QJsonDocument ChampCache::getChamps() { - QFile champsfile(QString::fromStdString(basefolder + "champs.json")); + QFile champsfile(basefolder + "champs.json"); if(ageOfFile(champsfile) < (qint64) maxage) { champsfile.open(QFile::ReadOnly); @@ -39,16 +39,16 @@ QJsonDocument ChampCache::getChamps() { return {}; // empty document } -void ChampCache::saveChamps(QJsonDocument doc, const std::string& version) { +void ChampCache::saveChamps(QJsonDocument doc, const QString& version) { QByteArray arr = doc.toJson(); - QFile champsfile(QString::fromStdString(basefolder + "champs.json")); + QFile champsfile(basefolder + "champs.json"); champsfile.open(QFile::WriteOnly | QFile::Truncate); champsfile.write(arr); - QFile versionfile(QString::fromStdString(basefolder + "version")); + QFile versionfile(basefolder + "version"); versionfile.open(QFile::WriteOnly | QFile::Truncate); - versionfile.write(version.c_str()); + versionfile.write(version.toLocal8Bit()); versionfile.close(); - Log::info << "saved Champs and version Cache"; + qInfo() << "saved Champs and version Cache"; } diff --git a/src/championsearch.cpp b/src/championsearch.cpp index 4148353..6ca480e 100644 --- a/src/championsearch.cpp +++ b/src/championsearch.cpp @@ -20,10 +20,10 @@ ChampRow* ChampionSearch::getSearchResult() { } void ChampionSearch::searchChanged(QString str) { - Log::info << "champion search: " << str.toStdString(); + qInfo() << "champion search: " << str; - const std::vector champs = dd->getMatchingChamp(str.toStdString()); - Log::info << "found " << champs.size() << " champs"; + const std::vector champs = dd->getMatchingChamp(str); + qInfo() << "found " << champs.size() << " champs"; clear(); diff --git a/src/champrow.cpp b/src/champrow.cpp index c3810b3..0801c06 100644 --- a/src/champrow.cpp +++ b/src/champrow.cpp @@ -7,14 +7,12 @@ ChampRow::~ChampRow() { } void ChampRow::setChamp(const DataDragon::ChampData& cd, QPixmap icon) { - setText(QString::fromStdString(cd.name)); + setText(cd.name); champid = cd.key; this->icon = icon; setIcon(QIcon(icon)); - #define QS(A) arg(QString::fromStdString(A)) - setToolTip(QWidget::tr("Champion: %1\nType: %2\nTitle: %3\nID: %4").QS(cd.name).QS(cd.partype).QS(cd.title).arg(cd.key)); - #undef QS + setToolTip(QWidget::tr("Champion: %1\nType: %2\nTitle: %3\nID: %4").arg(cd.name).arg(cd.partype).arg(cd.title).arg(cd.key)); } QString ChampRow::getChamp() const { diff --git a/src/clientaccess.cpp b/src/clientaccess.cpp index 957fce7..b3c9157 100644 --- a/src/clientaccess.cpp +++ b/src/clientaccess.cpp @@ -2,39 +2,39 @@ #include #include -#include + +#include +#include ClientAccess::ClientAccess() {} -ClientAccess::ClientAccess(const std::string& token, uint16_t port) : authcode(token), port(port) {} +ClientAccess::ClientAccess(const QString& token, uint16_t port) : authcode(token), port(port) {} std::shared_ptr createFromLockfile(std::istream& lockfile) { - std::vector parts; + std::string content; - while(std::getline(lockfile, content, ':')) { - parts.push_back(content); - } + std::getline(lockfile, content); + QStringList parts = QString::fromStdString(content).split(':'); if(parts.size() != 5) { - Log::error << "lockfile contained " << parts.size() << " parts, expected 5"; + qCritical() << "lockfile contained " << parts.size() << " parts, expected 5"; return {}; } - const std::string portstr = parts.at(2); - const std::string token = parts.at(3); + const QString portstr = parts.at(2); + const QString token = parts.at(3); // try to parse port - try { - uint16_t port = std::stoi(portstr); - - return std::shared_ptr(new ClientAccess(token, port)); - } catch(std::exception& e) { - Log::error << "could not parse port: " << std::quoted(portstr); + bool success = false; + uint16_t port = portstr.toUInt(&success); + if(!success) { + qCritical() << "could not parse port: " << portstr; + return nullptr; } - return nullptr; + return std::shared_ptr(new ClientAccess(token, port)); } -std::string ClientAccess::getBasicAuth() const { +QString ClientAccess::getBasicAuth() const { return "riot:" + authcode; } @@ -42,6 +42,6 @@ uint16_t ClientAccess::getPort() const { return port; } -std::string ClientAccess::getURL() const { - return "https://127.0.0.1:" + std::to_string(port) + "/"; +QString ClientAccess::getURL() const { + return "https://127.0.0.1:" + QString::number(port) + "/"; } diff --git a/src/clientaccess_linux.cpp b/src/clientaccess_linux.cpp index b54a101..9c3922d 100644 --- a/src/clientaccess_linux.cpp +++ b/src/clientaccess_linux.cpp @@ -19,22 +19,18 @@ #include "defer.h" -static const std::string CLIENTNAME = "LeagueClientUx.exe"; // returns the name and value of a argument or empty string if it could not be parsed +static const QString CLIENTNAME = "LeagueClientUx.exe"; // returns the name and value of a argument or empty string if it could not be parsed -static std::shared_ptr findUsingLockfile(const std::vector& cmdline, pid_t pid); - -static bool endsWith(const std::string& all, const std::string& end) { - return all.size() >= end.size() && all.rfind(end) == all.size() - end.size(); -} +static std::shared_ptr findUsingLockfile(const std::vector& cmdline, pid_t pid); // reads a procfile into a vector (strings are \0 seperated) -static std::vector readProcFile(const std::string& path) { - std::ifstream in(path); - std::vector out; +static std::vector readProcFile(const QString& path) { + std::ifstream in(path.toStdString()); + std::vector out; std::string line; while(std::getline(in, line, '\0')) { if(!line.empty()) { - out.push_back(line); + out.push_back(QString::fromStdString(line)); } } return out; @@ -51,27 +47,27 @@ std::shared_ptr ClientAccess::find() { while ((entry = readdir(procdir)) != NULL) { if (entry->d_type != DT_DIR) continue; - std::string name(entry->d_name); + QString name(entry->d_name); pid_t pid = -1; - try { - pid = std::stoi(name); - } catch(std::exception& e) { + bool success = false; + pid = name.toULong(&success); + if(!success) { // could not parse -> not a pid continue; } // get info on the exe - std::string cmdfile = "/proc/" + std::to_string(pid) + "/cmdline"; - std::vector args = readProcFile(cmdfile); + QString cmdfile = "/proc/" + QString::number(pid) + "/cmdline"; + std::vector args = readProcFile(cmdfile); - // Log::debug << "process: " << pid << " has " << args.size() << " args"; + // qDebug() << "process: " << pid << " has " << args.size() << " args"; if(args.empty()) continue; - std::string& exename = args.at(0); - if(endsWith(exename, CLIENTNAME)) { - Log::info << CLIENTNAME << " found: " << exename; + QString& exename = args.at(0); + if(exename.endsWith(CLIENTNAME)) { + qInfo() << CLIENTNAME << " found: " << exename; std::shared_ptr out; @@ -86,32 +82,32 @@ std::shared_ptr ClientAccess::find() { return nullptr; } -std::shared_ptr findUsingLockfile(const std::vector& cmdline, pid_t pid) { +std::shared_ptr findUsingLockfile(const std::vector& cmdline, pid_t pid) { // get WINEPREFIX env - std::vector envs = readProcFile("/proc/" + std::to_string(pid) + "/environ"); + std::vector envs = readProcFile("/proc/" + QString::number(pid) + "/environ"); - const static std::string WINEPREFIX = "WINEPREFIX="; + const static QString WINEPREFIX = "WINEPREFIX="; // find WINEPREFIX - auto found = std::find_if(envs.begin(), envs.end(), [](const std::string& s) { - return s.find(WINEPREFIX) == 0; + auto found = std::find_if(envs.begin(), envs.end(), [](const QString& s) { + return s.startsWith(WINEPREFIX); }); // WINEPREFIX env not present if(found == envs.end()) { - Log::debug << "WINEPREFIX environment variable not set"; + qDebug() << "WINEPREFIX environment variable not set"; return {}; } - const std::string wineprefix = found->substr(WINEPREFIX.size()); - const std::string binarypath = cmdline.at(0); - std::string gamefolder = binarypath.substr(2, binarypath.rfind('/')-1); // remove the "C:" and the name of the binary + const QString wineprefix = found->remove(0, WINEPREFIX.size()); + const QString binarypath = cmdline.at(0); + QString gamefolder = binarypath.mid(2, binarypath.lastIndexOf('/')-1); // remove the "C:" and the name of the binary // TODO: gamefoldre could contain '\' so replacing every occurance with '/' would be a good idea - const std::string lockfilepath = wineprefix + "/drive_c/" + gamefolder + "/lockfile"; + const QString lockfilepath = wineprefix + "/drive_c/" + gamefolder + "/lockfile"; - Log::debug << "lockfilepath: " << std::quoted(lockfilepath); + qDebug() << "lockfilepath: " << lockfilepath; // read lockfile - std::ifstream lockfile(lockfilepath); + std::ifstream lockfile(lockfilepath.toStdString()); return createFromLockfile(lockfile); } diff --git a/src/clientaccess_windows.cpp b/src/clientaccess_windows.cpp index 365d0f6..89a8c48 100644 --- a/src/clientaccess_windows.cpp +++ b/src/clientaccess_windows.cpp @@ -16,10 +16,10 @@ #include "defer.h" -static const std::string CLIENTNAME = "LeagueClientUx.exe"; +static const QString CLIENTNAME = "LeagueClientUx.exe"; -static std::string narrow(WCHAR* str, size_t len) { - std::string out; +static QString narrow(WCHAR* str, size_t len) { + QString out; out.reserve(len); for(uint32_t i = 0; i < len && str[i]; ++i) { out.append(1, (char) str[i]); @@ -27,11 +27,11 @@ static std::string narrow(WCHAR* str, size_t len) { return out; } -static std::string getProcessPath(DWORD dwPID) { +static QString getProcessPath(DWORD dwPID) { // Take a snapshot of all modules in the specified process. HANDLE hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID ); if(hModuleSnap == INVALID_HANDLE_VALUE) { - Log::error << "CreateToolhelp32Snapshot (of modules) failed"; + qCritical() << "CreateToolhelp32Snapshot (of modules) failed"; return {}; // empty string } @@ -44,7 +44,7 @@ static std::string getProcessPath(DWORD dwPID) { // Retrieve information about the first module, // and exit if unsuccessful if( !Module32First( hModuleSnap, &me32 ) ) { - Log::error << "Module32First"; + qCritical() << "Module32First"; return {}; } @@ -52,15 +52,15 @@ static std::string getProcessPath(DWORD dwPID) { } static std::shared_ptr findUsingLockfile(PROCESSENTRY32& proc) { - const std::string exepath = getProcessPath(proc.th32ProcessID); + const QString exepath = getProcessPath(proc.th32ProcessID); Log::note << "exepath: " << exepath; // lockfile path - const std::string lockfilepath = exepath.substr(0, exepath.rfind('\\')+1) + "lockfile"; // possible out of bounds - Log::debug << "Lockfile: " << lockfilepath; + const QString lockfilepath = exepath.substr(0, exepath.rfind('\\')+1) + "lockfile"; // possible out of bounds + qDebug() << "Lockfile: " << lockfilepath; std::ifstream lockfile(lockfilepath); if(!lockfile) { - Log::error << "lockfile could not be opend"; + qCritical() << "lockfile could not be opend"; return nullptr; } return createFromLockfile(lockfile); @@ -72,7 +72,7 @@ std::shared_ptr ClientAccess::find() { // Take a snapshot of all processes in the system. HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) { - Log::error << "CreateToolhelp32Snapshot (of processes) failed"; + qCritical() << "CreateToolhelp32Snapshot (of processes) failed"; return nullptr; } @@ -85,18 +85,18 @@ std::shared_ptr ClientAccess::find() { // Retrieve information about the first process, // and exit if unsuccessful if (!Process32First(hProcessSnap, &pe32)) { - Log::error << "Process32First failed"; // show cause of failure + qCritical() << "Process32First failed"; // show cause of failure return nullptr; } // Now walk the snapshot of processes, and // display information about each process in turn do { - std::string exename = narrow((WCHAR*) pe32.szExeFile, sizeof(pe32.szExeFile)); + QString exename = narrow((WCHAR*) pe32.szExeFile, sizeof(pe32.szExeFile)); // Log::note << "found process: " << exename; if(exename == CLIENTNAME) { - Log::info << CLIENTNAME << " found"; + qInfo() << CLIENTNAME << " found"; std::shared_ptr out; diff --git a/src/clientapi.cpp b/src/clientapi.cpp index 6bbe3c1..47bb7af 100644 --- a/src/clientapi.cpp +++ b/src/clientapi.cpp @@ -30,9 +30,9 @@ ClientAPI::GameflowPhase ClientAPI::getGameflowPhase() { // it is just a json-string no object QByteArray data = requestRaw("lol-gameflow/v1/gameflow-phase"); - std::string datastr = data.toStdString(); + QString datastr = QString::fromLocal8Bit(data); if (data.size() > 2) { - datastr = datastr.substr(1, datastr.size() -2); + datastr = datastr.mid(1, datastr.size() -2); return toGameflowPhase(datastr); } @@ -63,25 +63,25 @@ bool ClientAPI::setChampSelectAction(int32_t actionid, int32_t champid, bool com requestj["completed"] = completed; requestj["id"] = actionid; QJsonDocument requestdoc(requestj); - const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString(); - Log::debug << "requeststr: " << requeststr; - QJsonDocument doc = request("lol-champ-select/v1/session/actions/" + std::to_string(actionid), Method::PATCH, requeststr); + const QString requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact); + qDebug() << "requeststr: " << requeststr; + QJsonDocument doc = request("lol-champ-select/v1/session/actions/" + QString::number(actionid), Method::PATCH, requeststr); - std::string error; + QString error; if(doc.isObject()) { QJsonObject obj = doc.object(); auto errref = obj["errorCode"]; auto msgref = obj["message"]; if(errref.isString()) { - error = errref.toString().toStdString() + " "; + error = errref.toString() + " "; } if(msgref.isString()) { - error += msgref.toString().toStdString(); + error += msgref.toString(); } } - Log::note << "patching action: " << actionid << " error: " << error; - return error.empty(); + qDebug() << "patching action: " << actionid << " error: " << error; + return error.isEmpty(); } ClientAPI::PlayerInfo ClientAPI::getSelf() { @@ -91,15 +91,15 @@ ClientAPI::PlayerInfo ClientAPI::getSelf() { QJsonObject obj = doc.object(); PlayerInfo info; - info.gameName = getValue(obj, "gameName"); - info.name = getValue(obj, "name"); - info.statusMessage = getValue(obj, "statusMessage", ""); + info.gameName = getValue(obj, "gameName"); + info.name = getValue(obj, "name"); + info.statusMessage = getValue(obj, "statusMessage", ""); info.summonerid = getValue(obj, "summonerId"); auto lolref = obj["lol"]; if(lolref.isObject()) { QJsonObject lol = lolref.toObject(); - info.puuid = getValue(lol, "puuid"); + info.puuid = getValue(lol, "puuid"); info.level = getValue(lol, "level"); } @@ -165,32 +165,32 @@ std::vector ClientAPI::getAllConversations() { return out; } -ClientAPI::Message ClientAPI::sendMessage(const std::string& chatid, const std::string& messagebody) { +ClientAPI::Message ClientAPI::sendMessage(const QString& chatid, const QString& messagebody) { QJsonObject requestj; - requestj["body"] = QString::fromStdString(messagebody); + requestj["body"] = messagebody; QJsonDocument requestdoc(requestj); - const std::string requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString(); - Log::debug << "requeststr: " << requeststr; + const QString requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact); + qDebug() << "requeststr: " << requeststr; QJsonDocument doc = request("lol-chat/v1/conversations/" + chatid + "/messages", Method::POST, requeststr); - std::string error; + QString error; if(doc.isObject()) { QJsonObject obj = doc.object(); auto errref = obj["errorCode"]; auto msgref = obj["message"]; if(errref.isString()) { - error = errref.toString().toStdString() + " "; + error = errref.toString() + " "; } if(msgref.isString()) { - error += msgref.toString().toStdString(); + error += msgref.toString(); } - if(error.empty()) { + if(error.isEmpty()) { return (Message) obj; } } - Log::note << "send message error: " << error; + qDebug() << "send message error: " << error; return {}; } @@ -220,12 +220,12 @@ std::vector ClientAPI::getAllRunePages() { } bool ClientAPI::selectRunePage(uint64_t id) { - QJsonDocument doc = request("lol-perks/v1/currentpage", Method::PUT, std::to_string(id)); + QJsonDocument doc = request("lol-perks/v1/currentpage", Method::PUT, QString::number(id)); if(doc.isEmpty()) return true; // ok // error - qWarning() << "error selecting runepage: " << id << " " << doc.toJson().toStdString(); + qWarning() << "error selecting runepage: " << id << " " << doc.toJson(); return false; } @@ -233,7 +233,7 @@ bool ClientAPI::selectRunePage(uint64_t id) { bool ClientAPI::editRunePage(const RunePage& page) { QJsonObject pagereq; - pagereq["name"] = QString::fromStdString(page.name); + pagereq["name"] = page.name; pagereq["primaryStyleId"] = (int) page.runepage.primaryStyle; pagereq["subStyleId"] = (int) page.runepage.secondaryStyle; @@ -245,14 +245,14 @@ bool ClientAPI::editRunePage(const RunePage& page) { pagereq["selectedPerkIds"] = selected; QJsonDocument reqdoc(pagereq); - const std::string requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString(); + const QString requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact); qInfo() << "requeststr: " << requestdocstr; - QJsonDocument doc = request("lol-perks/v1/pages/" + std::to_string(page.id), Method::PUT, requestdocstr); + QJsonDocument doc = request("lol-perks/v1/pages/" + QString::number(page.id), Method::PUT, requestdocstr); if(doc.isEmpty()) return true; // ok // error - qWarning() << "error editing runepage: " << page.id << " " << doc.toJson().toStdString(); + qWarning() << "error editing runepage: " << page.id << " " << doc.toJson(); return false; } @@ -260,7 +260,7 @@ bool ClientAPI::editRunePage(const RunePage& page) { bool ClientAPI::createRunePage(const RunePage& page) { QJsonObject pagereq; - pagereq["name"] = QString::fromStdString(page.name); + pagereq["name"] = page.name; pagereq["primaryStyleId"] = (int) page.runepage.primaryStyle; pagereq["subStyleId"] = (int) page.runepage.secondaryStyle; @@ -272,25 +272,25 @@ bool ClientAPI::createRunePage(const RunePage& page) { pagereq["selectedPerkIds"] = selected; QJsonDocument reqdoc(pagereq); - const std::string requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact).toStdString(); + const QString requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact); qInfo() << "requeststr: " << requestdocstr; QJsonDocument doc = request("lol-perks/v1/pages/", Method::POST, requestdocstr); if(doc.isEmpty()) return true; // ok // error - qWarning() << "error creating runepage: " << page.name << " " << doc.toJson().toStdString(); + qWarning() << "error creating runepage: " << page.name << " " << doc.toJson(); return false; } bool ClientAPI::deleteRunePage(uint64_t id) { - QJsonDocument doc = request("lol-perks/v1/pages/" + std::to_string(id), Method::DELETE); + QJsonDocument doc = request("lol-perks/v1/pages/" + QString::number(id), Method::DELETE); if(doc.isEmpty()) return true; // ok // error - qWarning() << "error deleteing runepage: " << id << " " << doc.toJson().toStdString(); + qWarning() << "error deleteing runepage: " << id << " " << doc.toJson(); return false; } @@ -336,26 +336,26 @@ std::vector ClientAPI::getAllRuneStyles() { QPixmap ClientAPI::getImageResource(QString path) { if(path.isEmpty()) return {}; - std::string simplePath; + QString simplePath; { QString simplePathQ = path; - simplePath = simplePathQ.replace('/', '_').toStdString(); + simplePath = simplePathQ.replace('/', '_'); } // query mem cache - QPixmap img = memImageCache.getImage(path.toStdString(), 0); + QPixmap img = memImageCache.getImage(path, 0); if(!img.isNull()) return img; // query HDD cache img = imageCache.getImage(simplePath); if(!img.isNull()) { // update mem cache - memImageCache.addImage(img, path.toStdString(), 0); + memImageCache.addImage(img, path, 0); return img; } qInfo() << "requesting: " << path; - QByteArray arr = requestRaw(path.toStdString()); + QByteArray arr = requestRaw(path); QPixmap out; out.loadFromData(arr); @@ -363,7 +363,7 @@ QPixmap ClientAPI::getImageResource(QString path) { imageCache.addImageRaw(arr, simplePath); // store memchache - memImageCache.addImage(out, path.toStdString(), 0); + memImageCache.addImage(out, path, 0); return out; } diff --git a/src/clientapi_json.cpp b/src/clientapi_json.cpp index 3abf9cf..2a43419 100644 --- a/src/clientapi_json.cpp +++ b/src/clientapi_json.cpp @@ -1,6 +1,5 @@ #include "clientapi.h" -#include #include #include @@ -10,7 +9,7 @@ // calculate the size of a constant sized array #define ARRSIZE(ARRNAME) (sizeof(ARRNAME) / sizeof(ARRNAME[0])) -#define ARR(NAME, ...) static const std::string NAME ## Names[] = {__VA_ARGS__}; \ +#define ARR(NAME, ...) static const QString NAME ## Names[] = {__VA_ARGS__}; \ static const uint32_t NAME ## NamesCount = ARRSIZE(NAME ## Names); ARR(ReadyCheckState, "Invalid", "None", "InProgress", "Accepted", "Declined"); @@ -21,8 +20,8 @@ ARR(ShortPosition, "", "Top", "Jgl", "Mid", "Bot", "Sup"); ARR(ChampSelectActionType, "Invalid", "ban", "pick", "ten_bans_reveal"); template -static T mapEnum(const std::string& input, const std::string* names, uint32_t count, T defaul) { - if(input.empty()) return defaul; +static T mapEnum(const QString& input, const QString* names, uint32_t count, T defaul) { + if(input.isEmpty()) return defaul; for (uint32_t i = 0; i < count; ++i) { if (names[i] == input) { @@ -30,7 +29,7 @@ static T mapEnum(const std::string& input, const std::string* names, uint32_t co } } - Log::warn << "no mapping of enum-string: " << std::quoted(input) << " using default: " << defaul << " type: " << typeid(T).name(); + qWarning() << "no mapping of enum-string: " << input << " using default: " << defaul << " type: " << typeid(T).name(); return defaul; } @@ -50,8 +49,8 @@ static std::vector readVector(QJsonArray arr) { } ClientAPI::ReadyCheckState ClientAPI::toReadyCheckState(const QJsonObject& obj) { - std::string searchState = getValue(obj, "state", "Invalid"); - std::string playerresponse = getValue(obj, "playerResponse", "None"); + QString searchState = getValue(obj, "state", "Invalid"); + QString playerresponse = getValue(obj, "playerResponse", "None"); ClientAPI::ReadyCheckState response = MAPENUM(playerresponse, ReadyCheckState, NONE); @@ -65,27 +64,27 @@ ClientAPI::ReadyCheckState ClientAPI::toReadyCheckState(const QJsonObject& obj) return response; } -ClientAPI::GameflowPhase ClientAPI::toGameflowPhase(const std::string& str) { +ClientAPI::GameflowPhase ClientAPI::toGameflowPhase(const QString& str) { return MAPENUM(str, GameflowPhase, NONE); } -ClientAPI::ChampSelectPhase ClientAPI::toChampSelectPhase(const std::string& str) { +ClientAPI::ChampSelectPhase ClientAPI::toChampSelectPhase(const QString& str) { return MAPENUM(str, ChampSelectPhase, INVALID); } -Position toPosition(const std::string& str) { +Position toPosition(const QString& str) { return mapEnum(str, PositionNames, PositionNamesCount, Position::INVALID); } -std::string toString(Position p) { +QString toString(Position p) { return PositionNames[(int) p]; } -std::string toShortString(Position p) { +QString toShortString(Position p) { return ShortPositionNames[(int) p]; } -ClientAPI::ChampSelectActionType ClientAPI::toChampSelectActionType(const std::string& str) { +ClientAPI::ChampSelectActionType ClientAPI::toChampSelectActionType(const QString& str) { return MAPENUM(str, ChampSelectActionType, INVALID); } @@ -95,7 +94,7 @@ ClientAPI::TimerInfo::TimerInfo(const QJsonObject& obj) { internalNowInEpochMs = getValue(obj, "internalNowInEpochMs", 0); isefinite = getValue(obj, "isefinite", 0); - phase = MAPENUM(getValue(obj, "phase", "Invalid"), ChampSelectPhase, INVALID); + phase = MAPENUM(getValue(obj, "phase", "Invalid"), ChampSelectPhase, INVALID); totalTimeInPhase = getValue(obj, "totalTimeInPhase", 0); } @@ -108,13 +107,13 @@ ClientAPI::ChampSelectAction::ChampSelectAction(const QJsonObject& json) { id = getValue(json, "id"); isAllyAction = getValue(json, "isAllyAction"); isInProgress = getValue(json, "isInProgress"); - const std::string typestr = getValue(json, "type", "Invalid"); + const QString typestr = getValue(json, "type", "Invalid"); type = toChampSelectActionType(typestr); } ClientAPI::ChampSelectCell::ChampSelectCell() {} ClientAPI::ChampSelectCell::ChampSelectCell(const QJsonObject& json) { - position = toPosition(getValue(json, "assignedPosition")); + position = toPosition(getValue(json, "assignedPosition")); cellID = getValue(json, "cellId"); championID = getValue(json, "championId"); championPickIntentID = getValue(json, "championPickIntent"); @@ -195,7 +194,7 @@ ClientAPI::RunePage::RunePage(const QJsonObject& json) { lastmodified = getValue(json, "lastModified", 0); runepage.primaryStyle = getValue(json, "primaryStyleId", 0); runepage.secondaryStyle = getValue(json, "subStyleId", 0); - name = getValue(json, "name"); + name = getValue(json, "name"); isDeleteable = getValue(json, "isDeletable", false); isEditable = getValue(json, "isEditable", false); isActive = getValue(json, "isActive", false); @@ -222,9 +221,9 @@ RuneStyleSlot::RuneStyleSlot(const QJsonObject& json) { RuneStyle::RuneStyle() {} RuneStyle::RuneStyle(const QJsonObject& json) { id = getValue(json, "id", 0); - name = getValue(json, "name"); - iconPath = getValue(json, "iconPath"); - tooltip = getValue(json, "tooltip"); + name = getValue(json, "name"); + iconPath = getValue(json, "iconPath"); + tooltip = getValue(json, "tooltip"); idName = getValue(json, "idName"); auto subStylesRef = json["allowedSubStyles"]; @@ -242,36 +241,36 @@ RuneStyle::RuneStyle(const QJsonObject& json) { RuneAspekt::RuneAspekt() {} RuneAspekt::RuneAspekt(const QJsonObject& json) { id = getValue(json, "id", 0); - name = getValue(json, "name"); - shortDesc = getValue(json, "shortDesc"); - longDesc = getValue(json, "longDesc"); - tooltip = getValue(json, "tooltip"); - iconPath = getValue(json, "iconPath"); + name = getValue(json, "name"); + shortDesc = getValue(json, "shortDesc"); + longDesc = getValue(json, "longDesc"); + tooltip = getValue(json, "tooltip"); + iconPath = getValue(json, "iconPath"); } ClientAPI::Message::Message() {} ClientAPI::Message::Message(const QJsonObject& json) { - body = getValue(json, "body"); - fromId = getValue(json, "fromId"); - fromPid = getValue(json, "fromPid"); + body = getValue(json, "body"); + fromId = getValue(json, "fromId"); + fromPid = getValue(json, "fromPid"); fromSummonerId = getValue(json, "fromSummonerId"); - id = getValue(json, "id"); + id = getValue(json, "id"); isHistorical = getValue(json, "isHistorical", true); - timestamp = getValue(json, "timestamp"); - type = getValue(json, "type"); + timestamp = getValue(json, "timestamp"); + type = getValue(json, "type"); } ClientAPI::Conversation::Conversation() {} ClientAPI::Conversation::Conversation(const QJsonObject& json) : lastMessage(nullptr) { - gameName = getValue(json, "gameName"); - gameTag = getValue(json, "gameTag"); - id = getValue(json, "id"); + gameName = getValue(json, "gameName"); + gameTag = getValue(json, "gameTag"); + id = getValue(json, "id"); isMuted = getValue(json, "isMuted"); - name = getValue(json, "name"); - password = getValue(json, "password"); - pid = getValue(json, "pid"); - targetRegion = getValue(json, "targetRegion"); - type = getValue(json, "type"); + name = getValue(json, "name"); + password = getValue(json, "password"); + pid = getValue(json, "pid"); + targetRegion = getValue(json, "targetRegion"); + type = getValue(json, "type"); unreadMessageCount = getValue(json, "unreadMessageCount"); auto msgref = json["lastMessage"]; @@ -283,6 +282,11 @@ ClientAPI::Conversation::Conversation(const QJsonObject& json) : lastMessage(nul #define PRINTENUM(ENUMNAME) \ std::ostream& operator<<(std::ostream& str, const ClientAPI:: ENUMNAME & state) { \ + assert(((uint32_t) state) < ENUMNAME ## NamesCount); \ + return str << ENUMNAME ## Names[(uint32_t) state].toStdString() << " (" << (uint32_t) state << ')'; \ + } \ + \ + QDebug operator<<(QDebug str, const ClientAPI:: ENUMNAME & state) { \ assert(((uint32_t) state) < ENUMNAME ## NamesCount); \ return str << ENUMNAME ## Names[(uint32_t) state] << " (" << (uint32_t) state << ')'; \ } @@ -295,6 +299,11 @@ PRINTENUM(ChampSelectActionType) // not using macro because its not in ClientAPI std::ostream& operator<<(std::ostream& str, const Position & state) { + assert(((uint32_t) state) < PositionNamesCount); + return str << PositionNames[(uint32_t) state].toStdString() << " (" << (uint32_t) state << ')'; +} + +QDebug operator<<(QDebug str, const Position & state) { assert(((uint32_t) state) < PositionNamesCount); return str << PositionNames[(uint32_t) state] << " (" << (uint32_t) state << ')'; } diff --git a/src/config.cpp b/src/config.cpp index 47d0817..947b435 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -19,7 +19,7 @@ Config::StageConfig::StageConfig() : enabled(false) {} Config::StageConfig::StageConfig(const QJsonObject& j) { if(j["champ"].isString()) { - champs.push_back(getValue(j, "champ")); + champs.push_back(getValue(j, "champ")); } if(j["champs"].isArray()) { QJsonArray jchamps = j["champs"].toArray(); @@ -27,7 +27,7 @@ Config::StageConfig::StageConfig(const QJsonObject& j) { if(jchamp.isString()) { QString jchampstr = jchamp.toString(); if(!jchampstr.isEmpty()) { - champs.push_back(jchampstr.toStdString()); + champs.push_back(jchampstr); } } } @@ -39,9 +39,9 @@ Config::StageConfig::operator QJsonObject() const { QJsonObject out; QJsonArray jchamps; - for(const std::string& champ : champs) { - if(!champ.empty()) { - jchamps.push_back(QString::fromStdString(champ)); + for(const QString& champ : champs) { + if(!champ.isEmpty()) { + jchamps.push_back(champ); } } @@ -55,9 +55,9 @@ Config::PositionConfig::PositionConfig() {} Config::PositionConfig::PositionConfig(const QJsonObject& j) { ban = getValue(j, "ban"); pick = getValue(j, "pick"); - position = toPosition(getValue(j, "position")); + position = toPosition(getValue(j, "position")); if((int) position < 0 || position > Position::UTILITY) { - Log::warn << "invalid config value \"position\""; + qWarning() << "invalid config value \"position\""; position = Position::MIDDLE; } } @@ -66,7 +66,7 @@ Config::PositionConfig::operator QJsonObject() const { out["ban"] = (QJsonObject) ban; out["pick"] = (QJsonObject) pick; - out["position"] = QString::fromStdString(toString(position)); + out["position"] = toString(position); return out; } @@ -194,7 +194,7 @@ Config::Config() { Config::~Config() {} bool Config::load() { - QFile conffile(QString::fromStdString(configFilePath)); + QFile conffile(configFilePath); if(!conffile.open(QIODevice::ReadOnly)) { qCritical() << "could not open configfile: " << configFilePath; return false; @@ -221,9 +221,9 @@ bool Config::load() { void Config::save() { mkdirs(configFolderPath); - QFile conffile(QString::fromStdString(configFilePath)); + QFile conffile(configFilePath); if(!conffile.open(QIODevice::WriteOnly)) { - Log::error << "could not open configfile: " << configFilePath; + qCritical() << "could not open configfile: " << configFilePath; return; } diff --git a/src/datadragon.cpp b/src/datadragon.cpp index 2603c3a..307030a 100644 --- a/src/datadragon.cpp +++ b/src/datadragon.cpp @@ -13,10 +13,10 @@ #include "json.h" -static const std::string BASEURL = "https://ddragon.leagueoflegends.com/"; +static const QString BASEURL = "https://ddragon.leagueoflegends.com/"; const DataDragon::ChampData DataDragon::EMPTYCHAMP; -DataDragon::DataDragon(const std::string& locale) : RestClient(BASEURL), locale(locale), cache({{"square", ".png"}, {"loading", "_0.jpg"}, {"splash", "_0.jpg"}}) { +DataDragon::DataDragon(const QString& locale) : RestClient(BASEURL), locale(locale), cache({{"square", ".png"}, {"loading", "_0.jpg"}, {"splash", "_0.jpg"}}) { startThread(); } @@ -27,16 +27,16 @@ DataDragon::~DataDragon() { DataDragon::ChampData::ChampData() : key(-1) {} DataDragon::ChampData::ChampData(const QJsonObject& source) { - name = getValue(source, "name", ""); - id = getValue(source, "id", ""); + name = getValue(source, "name", ""); + id = getValue(source, "id", ""); key = getValue(source, "key", -1); - partype = getValue(source, "partype", ""); - title = getValue(source, "title", ""); + partype = getValue(source, "partype", ""); + title = getValue(source, "title", ""); } -const std::string& DataDragon::getVersion() { +const QString& DataDragon::getVersion() { std::unique_lock lock(cachedatamutex); - while(version.empty() && shouldrun) { + while(version.isEmpty() && shouldrun) { cachedatacv.wait(lock); } return version; @@ -50,8 +50,8 @@ const std::vector& DataDragon::getChamps() { return champs; } -QPixmap DataDragon::getImage(const std::string& champid, ImageType imgtype, bool writeMemcache) { - if(champid.empty()) return {}; +QPixmap DataDragon::getImage(const QString& champid, ImageType imgtype, bool writeMemcache) { + if(champid.isEmpty()) return {}; // query mem cache QPixmap img = memcache.getImage(champid, (int) imgtype); @@ -65,8 +65,8 @@ QPixmap DataDragon::getImage(const std::string& champid, ImageType imgtype, bool return img; } - const std::string url = getImageUrl(champid, imgtype); - if(url.empty()) return {}; + const QString url = getImageUrl(champid, imgtype); + if(url.isEmpty()) return {}; QByteArray arr; @@ -74,14 +74,14 @@ QPixmap DataDragon::getImage(const std::string& champid, ImageType imgtype, bool arr = requestRaw(url); } catch(RestClient::WebException& e) {} if(arr.isEmpty()) { - Log::error << "image could not be loaded"; + qCritical() << "image could not be loaded"; return {}; } // propably an error if(arr.size() < 1000) { - Log::info << "small icon url: " << url; - Log::info << "content: " << std::string(arr.data(), arr.size()); + qInfo() << "small icon url: " << url; + qInfo() << "content: " << QString::fromLocal8Bit(arr); return {}; } @@ -102,7 +102,7 @@ QPixmap DataDragon::getImage(const std::string& champid, ImageType imgtype, bool return decodedImage; } -void DataDragon::getImageAsnyc(const std::string& champid, notifyImgfunc_t func, ImageType imgtype) { +void DataDragon::getImageAsnyc(const QString& champid, notifyImgfunc_t func, ImageType imgtype) { if(!func) return; { @@ -112,44 +112,40 @@ void DataDragon::getImageAsnyc(const std::string& champid, notifyImgfunc_t func, tasksnotemptycv.notify_one(); } -static std::string toLower(const std::string& in) { - return QString::fromStdString(in).toLower().toStdString(); -} - -static size_t startinglength(const std::string& original, const std::string& prefix) { - size_t i = 0; +static int startinglength(const QString& original, const QString& prefix) { + int i = 0; for(; i < original.size() && i < prefix.size(); ++i) { - if(original.substr(0, i+1) != prefix.substr(0, i+1)) { + if(original.left(i+1) != prefix.left(i+1)) { return i; } } return i; } -static size_t matchChamp(const DataDragon::ChampData& champ, const std::string& lower) { - std::string lowerid = toLower(champ.id); - std::string lowername = toLower(champ.name); +static size_t matchChamp(const DataDragon::ChampData& champ, const QString& lower) { + QString lowerid = champ.id.toLower(); + QString lowername = champ.name.toLower(); if(lowerid == lower || lowername == lower) { return lower.size(); } - size_t lengtha = startinglength(lowerid, lower); - size_t lengthb = startinglength(lowername, lower); + int lengtha = startinglength(lowerid, lower); + int lengthb = startinglength(lowername, lower); - return std::max(lengtha, lengthb); + return qMax(lengtha, lengthb); } -const DataDragon::ChampData& DataDragon::getBestMatchingChamp(const std::string& name, int* count) { +const DataDragon::ChampData& DataDragon::getBestMatchingChamp(const QString& name, int* count) { getChamps(); // for now: just check for a perfect hit - std::string lower = toLower(name); + QString lower = name.toLower(); int bestmatchingoffset = -1; - size_t bestmatchinglength = 0; + int bestmatchinglength = 0; uint32_t bestmatchingcount = 0; for(size_t offset = 0; offset < champs.size(); ++offset) { const ChampData& it = champs.at(offset); - size_t match = matchChamp(it, lower); + int match = matchChamp(it, lower); if(match > bestmatchinglength) { bestmatchinglength = match; bestmatchingcount = 1; @@ -171,12 +167,12 @@ const DataDragon::ChampData& DataDragon::getBestMatchingChamp(const std::string& return EMPTYCHAMP; } -std::vector DataDragon::getMatchingChamp(const std::string& name, uint32_t limit) { +std::vector DataDragon::getMatchingChamp(const QString& name, uint32_t limit) { if(limit == 0) return {}; - if(name.empty()) return {}; + if(name.isEmpty()) return {}; getChamps(); - std::string lower = toLower(name); + QString lower = name.toLower(); std::vector matches; matches.resize(champs.size()); @@ -212,11 +208,11 @@ const DataDragon::ChampData* DataDragon::getChampByID(uint32_t id) { return &*it; } -std::vector DataDragon::resolveChampIDs(const std::vector& champnames) { +std::vector DataDragon::resolveChampIDs(const std::vector& champnames) { std::vector out; out.reserve(champnames.size()); - std::transform(champnames.begin(), champnames.end(), std::insert_iterator(out, out.begin()), [this](const std::string& champname) { + std::transform(champnames.begin(), champnames.end(), std::insert_iterator(out, out.begin()), [this](const QString& champname) { auto cd = getBestMatchingChamp(champname); return cd.key; // might be 0 (invalid) }); @@ -224,10 +220,10 @@ std::vector DataDragon::resolveChampIDs(const std::vector return out; } -std::string DataDragon::getImageUrl(const std::string& champid, ImageType type) { +QString DataDragon::getImageUrl(const QString& champid, ImageType type) { switch(type) { case ImageType::SQUARE: { - if(getVersion().empty()) { + if(getVersion().isEmpty()) { return {}; } @@ -244,13 +240,13 @@ std::string DataDragon::getImageUrl(const std::string& champid, ImageType type) return {}; } -std::string DataDragon::getCDNString() const { +QString DataDragon::getCDNString() const { return "cdn/" + version + "/"; } -void DataDragon::prefetchChampImage(const std::string& champid, ImageType imgtype) { +void DataDragon::prefetchChampImage(const QString& champid, ImageType imgtype) { if(!cache[(int) imgtype].hasImage(champid)) { - Log::debug << "prefetch " << champid << " type: " << (int) imgtype; + qDebug() << "prefetch " << champid << " type: " << (int) imgtype; getImage(champid, imgtype, false); } } @@ -258,31 +254,31 @@ void DataDragon::prefetchChampImage(const std::string& champid, ImageType imgtyp void DataDragon::getVersionInternal() { std::unique_lock lock(cachedatamutex); - if(!version.empty()) return; + if(!version.isEmpty()) return; version = champCache.getVersion(); - if(!version.empty()) return; + if(!version.isEmpty()) return; try { QJsonDocument jversions = request("api/versions.json"); if(jversions.isArray()) { QJsonArray jverarr = jversions.array(); if(!jverarr.empty()) { - version = jverarr.at(0).toString().toStdString(); - Log::info << "got League version: " << version; + version = jverarr.at(0).toString(); + qInfo() << "got League version: " << version; lock.unlock(); cachedatacv.notify_all(); return; } } - Log::error << "error parsing version object"; + qCritical() << "error parsing version object"; } catch(RestClient::WebException& e) {} } void DataDragon::getChampsInternal() { std::unique_lock lock(cachedatamutex); - if(!champs.empty() && version.empty()) { + if(!champs.empty() && version.isEmpty()) { return; } @@ -316,7 +312,7 @@ void DataDragon::getChampsInternal() { } } } - Log::info << "loaded " << champs.size() << " champs from cache: " << cacheSuccessfull; + qInfo() << "loaded " << champs.size() << " champs from cache: " << cacheSuccessfull; lock.unlock(); cachedatacv.notify_all(); } @@ -358,7 +354,7 @@ void DataDragon::threadLoop() { lock.unlock(); auto it = notDownloadedImages.begin(); - std::string champid = *it; + QString champid = *it; notDownloadedImages.erase(it); prefetchChampImage(champid, ImageType::SQUARE); @@ -391,5 +387,5 @@ void DataDragon::threadLoop() { std::ostream& operator<<(std::ostream& str, const DataDragon::ChampData& cd) { - return str << "[n: " << cd.name << " " << " k: " << cd.key << " id: " << cd.id << "]"; + return str << "[n: " << cd.name.toStdString() << " " << " k: " << cd.key << " id: " << cd.id.toStdString() << "]"; } diff --git a/src/datadragonimagecache.cpp b/src/datadragonimagecache.cpp index 640c200..8458401 100644 --- a/src/datadragonimagecache.cpp +++ b/src/datadragonimagecache.cpp @@ -7,7 +7,7 @@ #include "files.h" -DataDragonImageCache::DataDragonImageCache(const std::string& folderextra, const std::string& imageext) : imageext(imageext) { +DataDragonImageCache::DataDragonImageCache(const QString& folderextra, const QString& imageext) : imageext(imageext) { // init cache dir cacheDir = getCache() + folderextra + "/"; @@ -15,21 +15,21 @@ DataDragonImageCache::DataDragonImageCache(const std::string& folderextra, const } DataDragonImageCache::~DataDragonImageCache() {} -bool DataDragonImageCache::hasImage(const std::string& name) { - QFile file(QString::fromStdString(getFilepath(name))); +bool DataDragonImageCache::hasImage(const QString& name) { + QFile file(getFilepath(name)); return file.size() > 1024; // a image with less than 1KiB? assume it would be readable (r-Permissions) } -QPixmap DataDragonImageCache::getImage(const std::string& name) { - return QPixmap(QString::fromStdString(getFilepath(name))); +QPixmap DataDragonImageCache::getImage(const QString& name) { + return QPixmap(getFilepath(name)); } -void DataDragonImageCache::addImageRaw(const QByteArray& arr, const std::string& name) { - QFile file(QString::fromStdString(getFilepath(name))); +void DataDragonImageCache::addImageRaw(const QByteArray& arr, const QString& name) { + QFile file(getFilepath(name)); file.open(QIODevice::WriteOnly); file.write(arr); } -std::string DataDragonImageCache::getFilepath(const std::string& name) const { +QString DataDragonImageCache::getFilepath(const QString& name) const { return cacheDir + name + imageext; } diff --git a/src/files.cpp b/src/files.cpp index 76761d5..0b2b291 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -2,6 +2,8 @@ #include +#include + #include #ifdef WIN32 @@ -11,45 +13,31 @@ #endif #ifdef WIN32 -#include -bool mkdirs(const std::string& path) { - return QDir::root().mkpath(QString::fromStdString(path)); -} - -std::string getHome() { +QString getHome() { const char* homevar = getenv("appdata"); if(homevar == nullptr) { - Log::warn << "%appdata% is not set! Defaulting to ./"; + qWarning() << "%appdata% is not set! Defaulting to ./"; return "./"; } - return std::string(homevar) + "/"; + return QString(homevar) + "/"; } #else -bool mkdirs(const std::string& path) { - size_t offset = 0; - while(offset < path.size()) { - offset = path.find('/', offset+1); - int res = mkdir(path.substr(0, offset).c_str(), S_IRWXU | S_IRWXG); // 770 - if(res == -1 && errno != EEXIST) { - // mkdirs failed - return false; - } - } - return true; -} - -std::string getHome() { +QString getHome() { const char* homevar = getenv("HOME"); if(homevar == nullptr) { - Log::warn << "$HOME is not set! Defaulting to ./"; + qWarning() << "$HOME is not set! Defaulting to ./"; return "./"; } - return std::string(homevar) + "/"; + return QString(homevar) + "/"; } #endif -std::string getCache() { +bool mkdirs(const QString& path) { + return QDir::root().mkpath(path); +} + +QString getCache() { return getHome() + CACHEPATH; } diff --git a/src/lolautoaccept.cpp b/src/lolautoaccept.cpp index 97630f9..e5fcb4d 100644 --- a/src/lolautoaccept.cpp +++ b/src/lolautoaccept.cpp @@ -22,22 +22,22 @@ LolAutoAccept::~LolAutoAccept() { void LolAutoAccept::setChamps(const std::vector& champs, State s) { if(s == State::LOBBY || s >= State::PICK) { - Log::warn << "setChamps() called on invalid State"; + qWarning() << "setChamps() called on invalid State"; return; } - Log::debug << "LolAutoAccept::setChamps"; + qDebug() << "LolAutoAccept::setChamps"; { std::lock_guard lock(stagesMutex); stages.at((int) s).champids = champs; stages.at((int) s).currentOffset = 0; } - Log::info << "set champs on state: " << (int) s << " count: " << champs.size(); + qInfo() << "set champs on state: " << (int) s << " count: " << champs.size(); } void LolAutoAccept::setEnabled(bool b, State s) { if(s > State::PICK) { - Log::warn << "setEnabled() called on invalid State"; + qWarning() << "setEnabled() called on invalid State"; return; } @@ -56,7 +56,7 @@ bool LolAutoAccept::init() { if(ca) { clientapi = std::make_shared(*ca.get()); auto selfinfo = clientapi->getSelf(); - Log::info << "selfinfo: gameName: " << selfinfo.gameName << " name: " << selfinfo.name << " summonerid: " << selfinfo.summonerid << " statusMessage: " << selfinfo.statusMessage << " puuid: " << selfinfo.puuid << " level: " << selfinfo.level; + qInfo() << "selfinfo: gameName: " << selfinfo.gameName << " name: " << selfinfo.name << " summonerid: " << selfinfo.summonerid << " statusMessage: " << selfinfo.statusMessage << " puuid: " << selfinfo.puuid << " level: " << selfinfo.level; } return (bool) clientapi; @@ -89,7 +89,7 @@ const std::vector& LolAutoAccept::getRuneAspekts() { if(runeaspekts.empty()) { if(clientapi) { runeaspekts = clientapi->getAllRuneAspekts(); - Log::info << "Loaded " << runeaspekts.size() << " rune aspekts"; + qInfo() << "Loaded " << runeaspekts.size() << " rune aspekts"; } } @@ -100,7 +100,7 @@ const std::vector& LolAutoAccept::getRuneStyles() { if(runestyles.empty()) { if(clientapi) { runestyles = clientapi->getAllRuneStyles(); - Log::info << "Loaded " << runestyles.size() << " rune styles"; + qInfo() << "Loaded " << runestyles.size() << " rune styles"; } } @@ -115,7 +115,7 @@ void LolAutoAccept::setOnRuneChangeFunc(onruneschange_func on) { onRuneschange = on; } -void LolAutoAccept::setAutoWriteText(bool enabled, const std::string& text) { +void LolAutoAccept::setAutoWriteText(bool enabled, const QString& text) { if ( enabled && !autoWriteTextEnabled ) { // only re-write on rising edge autoWriteTextDone = false; @@ -138,7 +138,7 @@ void LolAutoAccept::innerRun() { try { auto convs = clientapi->getAllConversations(); - Log::info << "got " << convs.size() << " conversations"; + qInfo() << "got " << convs.size() << " conversations"; emit statusChanged(Status::Running); while(shouldrun) { @@ -146,7 +146,7 @@ void LolAutoAccept::innerRun() { auto start = std::chrono::high_resolution_clock::now(); auto phase = clientapi->getGameflowPhase(); - Log::info << "current Gameflowphase: " << phase; + qInfo() << "current Gameflowphase: " << phase; // do processing if(phase == ClientAPI::GameflowPhase::LOBBY) { @@ -160,9 +160,9 @@ void LolAutoAccept::innerRun() { if(stages.at(0).enabled) { // auto accept enabled auto state = clientapi->getReadyCheckState(); - Log::info << "readychack state: " << state; + qInfo() << "readychack state: " << state; if(state == ClientAPI::ReadyCheckState::INPROGRESS) { - Log::info << "auto accepting"; + qInfo() << "auto accepting"; clientapi->acceptMatch(); } } @@ -202,7 +202,7 @@ void LolAutoAccept::innerRun() { } emit statusChanged(Status::Off); } catch(RestClient::WebException& e) { - Log::error << "WebException catched: " << e.curlresponse; + qCritical() << "WebException catched: " << e.curlresponse; if(e.curlresponse == CURLE_COULDNT_CONNECT) { // free clientapi clientapi.reset(); @@ -264,8 +264,8 @@ uint32_t LolAutoAccept::getChampOfState(State s) { uint32_t size = stage.champids.size(); if(stage.currentOffset >= size) { // no champ to try left - Log::warn << "no champ left at stage: " << (int) s; - Log::warn << "stage size: " << stage.champids.size(); + qWarning() << "no champ left at stage: " << (int) s; + qWarning() << "stage size: " << stage.champids.size(); return 0; } @@ -282,8 +282,8 @@ void LolAutoAccept::nextChampOfState(State s) { if(stage.currentOffset >= size) { // no champ to try left - Log::warn << "no champ left at stage: " << (int) s; - Log::warn << "stage size: " << stage.champids.size(); + qWarning() << "no champ left at stage: " << (int) s; + qWarning() << "stage size: " << stage.champids.size(); stage.currentOffset = 0; return; @@ -293,7 +293,7 @@ void LolAutoAccept::nextChampOfState(State s) { bool LolAutoAccept::isChampIntentofTeammate(uint32_t champid, const ClientAPI::ChampSelectSession& session) { for(const ClientAPI::ChampSelectCell& player : session.myTeam) { if(player.championID == (int32_t) champid || player.championPickIntentID == (int32_t) champid) { - Log::info << "player " << player.cellID << " @ " << player.position << " wants to play " << champid; + qInfo() << "player " << player.cellID << " @ " << toString(player.position) << " wants to play " << champid; return true; } } @@ -313,7 +313,7 @@ LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const s ownactions_t out; for(const auto& it : actions) { if(it.actorCellID == cellid) { - Log::debug << "ownaction: id: " << it.id << " champid: " << it.championID << " completed: " << it.completed << " type: " << it.type; + qDebug() << "ownaction: id: " << it.id << " champid: " << it.championID << " completed: " << it.completed << " type: " << it.type; if(!it.completed) { // completed cant be interacted anyways, so just ignore them. out.push_back(it); } @@ -344,7 +344,7 @@ void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelect for(auto it : ownactions) { if(it.type == type) { - Log::info << type << " action anvailable: " << it.id << " champid: " << it.championID; + qInfo() << type << " action anvailable: " << it.id << " champid: " << it.championID; uint32_t champid = getChampOfState(s); if(filter) { @@ -358,7 +358,7 @@ void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelect if((it.championID != (int32_t) champid || !it.completed) && champid != 0) { // try to prepick a champion - Log::info << "try to pick champ: " << champid; + qInfo() << "try to pick champ: " << champid; if(!clientapi->setChampSelectAction(it.id, champid, complete)) { nextChampOfState(s); @@ -370,15 +370,15 @@ void LolAutoAccept::phase(const ownactions_t& ownactions, ClientAPI::ChampSelect } int32_t LolAutoAccept::getBestRunePage(const std::vector& pages) { - Log::debug << "searching RunePages: " << pages.size(); + qDebug() << "searching RunePages: " << pages.size(); for(uint32_t i = 0; i < pages.size(); ++i) { - Log::debug << i << ": " << pages[i].id << " " << pages[i].name << " " << pages[i].isCurrent; + qDebug() << i << ": " << pages[i].id << " " << pages[i].name << " " << pages[i].isCurrent; } // search for a rune page with a name that starts with "AA: " for(uint32_t i = 0; i < pages.size(); ++i) { const ClientAPI::RunePage& rp = pages.at(i); - if(rp.name.size() >= 4 && rp.name.substr(0, 4) == "AA: ") { + if(rp.name.size() >= 4 && rp.name.left(4) == "AA: ") { return i; } } @@ -418,13 +418,13 @@ void LolAutoAccept::champSelect() { // check if runes need adjustment if(pickedChamp != lastPickedChamp) { - Log::info << "picked champ changed from: " << lastPickedChamp << " to: " << pickedChamp; + qInfo() << "picked champ changed from: " << lastPickedChamp << " to: " << pickedChamp; lastPickedChamp = pickedChamp; // update runes if(onRuneschange) { auto champinfo = blitzapi.getChampionInfo(pickedChamp, pos); // TODO: add detection for enemy champ - Log::info << "champinfo aquired: " << champinfo.runepage; + qInfo() << "champinfo aquired: " << champinfo.runepage; onRuneschange(champinfo.runepage); } @@ -438,13 +438,13 @@ void LolAutoAccept::champSelect() { emit positionChanged(pos); } - Log::debug << "cellid: " << cellid << " position: " << pos << " counter: " << session.counter << " timer: timeleftip: " << session.timer.adjustedTimeLeftInPhase << " totaltimephase: " << session.timer.totalTimeInPhase; + qDebug() << "cellid: " << cellid << " position: " << toString(pos) << " counter: " << session.counter << " timer: timeleftip: " << session.timer.adjustedTimeLeftInPhase << " totaltimephase: " << session.timer.totalTimeInPhase; // find actions for own cell auto ownactions = getOwnActions(cellid, session.actions); - Log::debug << "ownactions: " << ownactions.size(); + qDebug() << "ownactions: " << ownactions.size(); // try to prepick champ - Log::info << "champselectphase: " << session.timer.phase; + qInfo() << "champselectphase: " << session.timer.phase; std::lock_guard lock(stagesMutex); if(session.timer.phase == ClientAPI::ChampSelectPhase::PLANNING) { @@ -466,9 +466,9 @@ void LolAutoAccept::champSelect() { } // check for autowriteText - if(autoWriteTextEnabled && !autoWriteTextDone && !autoWriteText.empty()) { - const std::string& chatid = getChatid(); - if(!chatid.empty()) { + if(autoWriteTextEnabled && !autoWriteTextDone && !autoWriteText.isEmpty()) { + const QString& chatid = getChatid(); + if(!chatid.isEmpty()) { clientapi->sendMessage(chatid, autoWriteText); autoWriteTextDone = true; } @@ -478,7 +478,7 @@ void LolAutoAccept::champSelect() { void LolAutoAccept::smiteWarning(const std::vector& cells) { uint32_t smiteCount = 0; for(const ClientAPI::ChampSelectCell& member : cells) { - Log::info << "position: " << member.position << " spells: " << member.spell1Id << " " << member.spell2Id; + qInfo() << "position: " << toString(member.position) << " spells: " << member.spell1Id << " " << member.spell2Id; smiteCount += (member.spell1Id == 11 || member.spell2Id == 11); } @@ -489,24 +489,24 @@ void LolAutoAccept::smiteWarning(const std::vector& return; } - Log::info << "smite warning: " << smiteCount; - const std::string& chatid = getChatid(); - if(!chatid.empty()) { + qInfo() << "smite warning: " << smiteCount; + const QString& chatid = getChatid(); + if(!chatid.isEmpty()) { clientapi->sendMessage(chatid, "smite"); lastMessageSent = currenttime; } } } -const std::string& LolAutoAccept::getChatid() { - if(chatid.empty()) { +const QString& LolAutoAccept::getChatid() { + if(chatid.isEmpty()) { std::vector convs = clientapi->getAllConversations(); - Log::info << "got " << convs.size() << " conversations"; + qInfo() << "got " << convs.size() << " conversations"; for(const ClientAPI::Conversation& conv : convs) { - Log::info << " id: " << conv.id << " type: " << conv.type << " name: " << conv.name << " gameName: " << conv.gameName; - if(conv.type == "championSelect" && conv.name.empty()) { - Log::info << "groupchat found"; + qInfo() << " id: " << conv.id << " type: " << conv.type << " name: " << conv.name << " gameName: " << conv.gameName; + if(conv.type == "championSelect" && conv.name.isEmpty()) { + qInfo() << "groupchat found"; chatid = conv.id; return chatid; } @@ -521,7 +521,7 @@ void LolAutoAccept::applyRunes_internal(uint32_t champid, Position pos) { // get recommended runes and stuff auto champinfo = blitzapi.getChampionInfo(champid, pos); - Log::info << "fetched champion info runes: " << champinfo.runepage; + qInfo() << "fetched champion info runes: " << champinfo.runepage; // choose page auto pages = clientapi->getAllRunePages(); @@ -530,29 +530,29 @@ void LolAutoAccept::applyRunes_internal(uint32_t champid, Position pos) { int32_t choosepage = getMatchingRunePage(champinfo.runepage, pages); if(choosepage != -1) { ClientAPI::RunePage& page = pages.at(choosepage); - Log::info << "matching runepage found, selecting: " << page.id << " " << page.name; + qInfo() << "matching runepage found, selecting: " << page.id << " " << page.name; if(clientapi->selectRunePage(page.id)) { return; } - Log::warn << "selecting runepage failed"; + qWarning() << "selecting runepage failed"; } // find page to replace int32_t pageoffset = getBestRunePage(pages); if(pageoffset < 0) { - Log::warn << "no rune page found!"; + qWarning() << "no rune page found!"; return; } // replace the page ClientAPI::RunePage& rp = pages.at(pageoffset); - Log::info << "replace runepage id: " << rp.id << " old-name: " << rp.name; + qInfo() << "replace runepage id: " << rp.id << " old-name: " << rp.name; // resolve champion name for the runepage name ClientAPI::RunePage newpage; auto champ = dd.getChampByID(champid); - const std::string champname = champ ? champ->name : std::to_string(champid); + const QString champname = champ ? champ->name : QString::number(champid); newpage.id = rp.id; newpage.name = "AA: " + champname + " " + toShortString(pos); // TODO: make role "Utility" resolve to "Support"? @@ -561,9 +561,9 @@ void LolAutoAccept::applyRunes_internal(uint32_t champid, Position pos) { //select runepage if(!rp.isCurrent) { - Log::info << "page is not selected, selecting now (id: " << newpage.id << ')'; + qInfo() << "page is not selected, selecting now (id: " << newpage.id << ')'; clientapi->selectRunePage(newpage.id); } - Log::info << "runepage done"; + qInfo() << "runepage done"; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b8d48aa..e6ebe03 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5,7 +5,7 @@ #include -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name().toStdString()), +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name()), lolaa(conf.getConfig(), dd) { ui->setupUi(this); @@ -41,7 +41,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui ui->enableAutoWrite->setChecked(rc.enabledAutoWrite); ui->autoWriteText->setText(rc.autoWriteText); - lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText.toStdString()); + lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText); resizeEvent(nullptr); @@ -82,7 +82,7 @@ void MainWindow::toggleMainswitch(bool state) { // TODO: make this non blocking if(!lolaa.init()) { - Log::error << "League Client not found!"; + qCritical() << "League Client not found!"; ui->statusbar->showMessage(tr("League of Legends Client not found!")); ui->mainswitch->setCheckState(Qt::CheckState::Unchecked); ui->mainswitch->setEnabled(true); @@ -148,7 +148,7 @@ void MainWindow::autoWriteChanged() { bool enabled = ui->enableAutoWrite->isChecked(); const QString text = ui->autoWriteText->toPlainText(); - lolaa.setAutoWriteText(enabled, text.toStdString()); + lolaa.setAutoWriteText(enabled, text); conf.getConfig().enabledAutoWrite = enabled; conf.getConfig().autoWriteText = text; diff --git a/src/memoryimagecache.cpp b/src/memoryimagecache.cpp index 6305cbc..dc62666 100644 --- a/src/memoryimagecache.cpp +++ b/src/memoryimagecache.cpp @@ -5,7 +5,7 @@ MemoryImageCache::MemoryImageCache(size_t maxsize) : maxsize(maxsize) {} -void MemoryImageCache::addImage(QPixmap img, const std::string& title, int type) { +void MemoryImageCache::addImage(QPixmap img, const QString& title, int type) { auto it = std::find_if(cache.begin(), cache.end(), getImageMatcher(title, type)); if(it == cache.end()) { // insert new @@ -19,7 +19,7 @@ void MemoryImageCache::addImage(QPixmap img, const std::string& title, int type) it->imageref = img; } -QPixmap MemoryImageCache::getImage(const std::string& title, int type) { +QPixmap MemoryImageCache::getImage(const QString& title, int type) { auto it = std::find_if(cache.begin(), cache.end(), getImageMatcher(title, type)); if(it == cache.end()) { return {}; @@ -40,7 +40,7 @@ bool MemoryImageCache::CachedImage::operator<(const MemoryImageCache::CachedImag return lastaccessed < other.lastaccessed; } -std::function MemoryImageCache::getImageMatcher(const std::string& title, int type) { +std::function MemoryImageCache::getImageMatcher(const QString& title, int type) { return [title, type](const MemoryImageCache::CachedImage& img) -> bool { return img.type == type && img.title == title; }; diff --git a/src/restclient.cpp b/src/restclient.cpp index 5878b50..c14ea12 100644 --- a/src/restclient.cpp +++ b/src/restclient.cpp @@ -63,7 +63,7 @@ static int my_trace(CURL* handle, curl_infotype type, char* data, size_t size, v return 0; } -RestClient::RestClient(const std::string& base) : baseurl(base) { +RestClient::RestClient(const QString& base) : baseurl(base) { curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, arrayWriteCallback); @@ -77,13 +77,13 @@ RestClient::~RestClient() { RestClient::WebException::WebException(CURLcode c) : curlresponse(c) { } -QByteArray RestClient::requestRaw(const std::string& url, Method m, const std::string& data) { +QByteArray RestClient::requestRaw(const QString& url, Method m, const QString& data) { if (!curl) return {}; - std::string requrl = baseurl + url; - curl_easy_setopt(curl, CURLOPT_URL, requrl.c_str()); + QString requrl = baseurl + url; + curl_easy_setopt(curl, CURLOPT_URL, requrl.toLocal8Bit().data()); - curl_easy_setopt(curl, CURLOPT_USERPWD, basicauth.c_str()); + curl_easy_setopt(curl, CURLOPT_USERPWD, basicauth.toLocal8Bit().data()); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); if (disableCertCheck) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); @@ -106,22 +106,22 @@ QByteArray RestClient::requestRaw(const std::string& url, Method m, const std::s curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); break; case Method::POST: curl_easy_setopt(curl, CURLOPT_POST, 1L); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.toLocal8Bit().data()); headerlist = curl_slist_append(headerlist, "Content-Type: application/json"); break; case Method::PUT: curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); // to use the POSTFIELDS (do not use CURLOPT_PUT, it does not support POSTFIELDS) - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.toLocal8Bit().data()); headerlist = curl_slist_append(headerlist, "Content-Type: application/json"); break; case Method::PATCH: curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.toLocal8Bit().data()); headerlist = curl_slist_append(headerlist, "Content-Type: application/json"); break; case Method::DELETE: curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.toLocal8Bit().data()); headerlist = curl_slist_append(headerlist, "Content-Type: application/json"); break; } @@ -141,9 +141,9 @@ QByteArray RestClient::requestRaw(const std::string& url, Method m, const std::s if (res == CURLE_HTTP_RETURNED_ERROR) { long responsecode = -1; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responsecode); - Log::warn << "API request failed: " << baseurl << " " << url << " -> " << responsecode; + qWarning() << "API request failed: " << baseurl << " " << url << " -> " << responsecode; } else { - Log::warn << "API request failed: " << baseurl << " " << url << " " << curl_easy_strerror(res); + qWarning() << "API request failed: " << baseurl << " " << url << " " << curl_easy_strerror(res); if(res == CURLE_COULDNT_CONNECT) { throw WebException(res); } @@ -153,14 +153,14 @@ QByteArray RestClient::requestRaw(const std::string& url, Method m, const std::s return ba; } -QJsonDocument RestClient::request(const std::string& url, Method m, const std::string& data) { +QJsonDocument RestClient::request(const QString& url, Method m, const QString& data) { QByteArray arr = requestRaw(url, m, data); if (arr.isEmpty()) return {}; QJsonParseError err; QJsonDocument parsed = QJsonDocument::fromJson(arr, &err); if (parsed.isNull() || err.error != QJsonParseError::NoError) { - Log::error << "API Json parse error " << err.errorString().toStdString() << " offset: " << err.offset; + qCritical() << "API Json parse error " << err.errorString() << " offset: " << err.offset; return {}; } @@ -178,9 +178,9 @@ void RestClient::enableDebugging(bool enabled) { } } -std::string RestClient::escape(const std::string& in) const { - char* e = curl_easy_escape(curl, in.c_str(), in.length()); - std::string esc(e); +QString RestClient::escape(const QString& in) const { + char* e = curl_easy_escape(curl, in.toLocal8Bit().data(), in.length()); + QString esc(e); curl_free(e); return esc; } diff --git a/src/runedisplay.cpp b/src/runedisplay.cpp index f3e00bc..1566231 100644 --- a/src/runedisplay.cpp +++ b/src/runedisplay.cpp @@ -1,9 +1,9 @@ #include "runedisplay.h" #include "ui_runedisplay.h" -#include +#include -const static std::string EMPTY; +const static QString EMPTY; RuneDisplay::RuneDisplay(QWidget *parent) : QWidget(parent), ui(new Ui::RuneDisplay) { ui->setupUi(this); @@ -32,10 +32,11 @@ void RuneDisplay::applyRunesClicked() { } void RuneDisplay::updateText() { - std::ostringstream out; + QString outStr; + QTextStream out(&outStr); if(! (bool) runepage) { - ui->runetext->setText(QString::fromStdString("")); + ui->runetext->setText(""); ui->applyRunesBtn->setEnabled(false); return; } @@ -45,24 +46,24 @@ void RuneDisplay::updateText() { for(uint32_t rune : runepage.selectedAspects) { out << getRuneText(rune) << '\n'; } - ui->runetext->setText(QString::fromStdString(out.str())); + ui->runetext->setText(outStr); ui->applyRunesBtn->setEnabled(true); } -std::string RuneDisplay::getRuneText(uint32_t id) { +QString RuneDisplay::getRuneText(uint32_t id) { for(const RuneAspekt& ra : runeinfo) { if(ra.id == id) { return ra.name; } } - return "(" + std::to_string(id) + ")"; + return "(" + QString::number(id) + ")"; } -std::string RuneDisplay::getRuneStyleByID(uint32_t id) { +QString RuneDisplay::getRuneStyleByID(uint32_t id) { auto it = std::find_if(runestyles.begin(), runestyles.end(), [id](const RuneStyle& rs) { return rs.id == id; }); if(it == runestyles.end()) { - return '(' + std::to_string(id) + ')'; + return '(' + QString::number(id) + ')'; } return it->name; diff --git a/src/runeeditor.cpp b/src/runeeditor.cpp index 3396de4..5b9c96b 100644 --- a/src/runeeditor.cpp +++ b/src/runeeditor.cpp @@ -140,12 +140,12 @@ const RuneStyle* RuneEditor::getRuneStyle(uint32_t id) const { } RuneAspektButton* RuneEditor::createStyleButton(const RuneStyle& rs, bool selected) { - RuneAspektButton* styleBtn = createButtonFromResource(QString::fromStdString(rs.iconPath)); + RuneAspektButton* styleBtn = createButtonFromResource(rs.iconPath); if(!styleBtn) return nullptr; - styleBtn->setText(QString::fromStdString(rs.name)); - styleBtn->setToolTip(QString::fromStdString(rs.tooltip)); + styleBtn->setText(rs.name); + styleBtn->setToolTip(rs.tooltip); if(selected) { styleBtn->setStyleSheet("border: 1px solid red;"); @@ -155,12 +155,12 @@ RuneAspektButton* RuneEditor::createStyleButton(const RuneStyle& rs, bool select } RuneAspektButton* RuneEditor::createAspektButton(const RuneAspekt& ra) { - RuneAspektButton* aspektBtn = createButtonFromResource(QString::fromStdString(ra.iconPath)); + RuneAspektButton* aspektBtn = createButtonFromResource(ra.iconPath); if(!aspektBtn) return nullptr; - aspektBtn->setText(QString::fromStdString(ra.name)); - aspektBtn->setToolTip(QString::fromStdString(ra.tooltip)); + aspektBtn->setText(ra.name); + aspektBtn->setToolTip(ra.tooltip); aspektBtn->setAspektsVector(runepage.selectedAspects); aspektBtn->setAspektId(ra.id); diff --git a/src/runemanager.cpp b/src/runemanager.cpp index 76ea638..ce3b56e 100644 --- a/src/runemanager.cpp +++ b/src/runemanager.cpp @@ -115,7 +115,7 @@ void RuneManager::setRunesEnabled(bool enabled) { void RuneManager::saveRunePageClient(int id, QString name, const RunePage& rp) { if(client) { ClientAPI::RunePage newPage; - newPage.name = name.toStdString(); + newPage.name = name; newPage.runepage = rp; newPage.id = id; diff --git a/src/runepage.cpp b/src/runepage.cpp index 56d22ab..d1859e3 100644 --- a/src/runepage.cpp +++ b/src/runepage.cpp @@ -53,3 +53,7 @@ RunePage::RunePage(const QJsonObject& obj) : std::ostream& operator<<(std::ostream& str, const RunePage& rp) { return str << "Primary: " << rp.primaryStyle << " Secondary: " << rp.secondaryStyle << " aspects: " << rp.selectedAspects.size(); } + +QDebug operator<<(QDebug str, const RunePage& rp) { + return str << "Primary: " << rp.primaryStyle << " Secondary: " << rp.secondaryStyle << " aspects: " << rp.selectedAspects.size(); +} diff --git a/src/runepagelist.cpp b/src/runepagelist.cpp index 6467442..67b29d8 100644 --- a/src/runepagelist.cpp +++ b/src/runepagelist.cpp @@ -25,7 +25,7 @@ RunePageList::~RunePageList() { void RunePageList::loadRunePages(const std::vector& pages) { clearItems(); for(const ClientAPI::RunePage& rp : pages) { - addRunepageItem(QString::fromStdString(rp.name), rp.id, rp.runepage, rp.isCurrent); + addRunepageItem(rp.name, rp.id, rp.runepage, rp.isCurrent); } } @@ -202,7 +202,7 @@ void RunePageList::addRunepageItem(QString name, int id, const ::RunePage& rp, b item->setData(RolePointer, (qulonglong) new ::RunePage(rp)); if(dd) { - const DataDragon::ChampData& champData = dd->getBestMatchingChamp(name.toStdString()); + const DataDragon::ChampData& champData = dd->getBestMatchingChamp(name); if(champData.key != -1) { QPixmap iamge = dd->getImage(champData.id); item->setIcon(iamge); @@ -244,7 +244,7 @@ QString RunePageList::getRuneText(uint32_t id) { if(runeInfo != nullptr) { for(const RuneAspekt& ra : *runeInfo) { if(ra.id == id) { - return QString::fromStdString(ra.name); + return ra.name; } } } @@ -257,7 +257,7 @@ QString RunePageList::getRuneStyleByID(uint32_t id) { auto it = std::find_if(runeStyles->begin(), runeStyles->end(), [id](const RuneStyle& rs) { return rs.id == id; }); if(it != runeStyles->end()) { - return QString::fromStdString(it->name); + return it->name; } } diff --git a/src/settingstab.cpp b/src/settingstab.cpp index 3d2e5df..c8a3b6e 100644 --- a/src/settingstab.cpp +++ b/src/settingstab.cpp @@ -4,8 +4,8 @@ #include #include -static std::vector toChampionNameList(const std::vector& scs) { - std::vector out; +static std::vector toChampionNameList(const std::vector& scs) { + std::vector out; out.reserve(scs.size()); std::transform(scs.begin(), scs.end(), std::insert_iterator(out, out.begin()), [](const StageSettings::SelectedChamp& sc) { return sc.name; }); @@ -42,7 +42,7 @@ bool SettingsTab::getState(LolAutoAccept::State s) const { return stage->getState(); } -void SettingsTab::setChamps(LolAutoAccept::State s, const std::vector& c) { +void SettingsTab::setChamps(LolAutoAccept::State s, const std::vector& c) { getStage(s)->setChampions(c); } diff --git a/src/stagesettings.cpp b/src/stagesettings.cpp index 9a6ec70..2c27ea2 100644 --- a/src/stagesettings.cpp +++ b/src/stagesettings.cpp @@ -39,23 +39,23 @@ void StageSettings::setState(bool b) { updateEnabled(); } -StageSettings::SelectedChamp::SelectedChamp(std::string name, uint32_t id) : name(name), id(id) {} +StageSettings::SelectedChamp::SelectedChamp(QString name, uint32_t id) : name(name), id(id) {} std::vector StageSettings::getChampions() const { std::vector out; out.reserve(ui->championList->count()); for(int32_t i = 0; i < ui->championList->count(); ++i) { ChampRow* cr = (ChampRow*) ui->championList->item(i); - out.emplace_back(cr->getChamp().toStdString(), cr->getChampID()); + out.emplace_back(cr->getChamp(), cr->getChampID()); } return out; } -void StageSettings::setChampions(const std::vector& champs) { +void StageSettings::setChampions(const std::vector& champs) { clear(); // add new champs - for(const std::string& champ : champs) { + for(const QString& champ : champs) { resolveAndAddChamp(champ, champ == champs.back()); } } @@ -87,7 +87,7 @@ void StageSettings::addChamp() { // popup with champion search ChampionSearch cs(dd, this); int res = cs.exec(); - Log::info << "championsearch result: " << res; + qInfo() << "championsearch result: " << res; if(res == QDialog::Accepted) { auto cr = cs.getSearchResult(); if(cr) { @@ -110,7 +110,7 @@ void StageSettings::moved() { emit championsChanged(); } -void StageSettings::resolveAndAddChamp(const std::string& name, bool emitchange) { +void StageSettings::resolveAndAddChamp(const QString& name, bool emitchange) { if(dd) { int count = 0; auto cd = dd->getBestMatchingChamp(name, &count); @@ -122,7 +122,7 @@ void StageSettings::resolveAndAddChamp(const std::string& name, bool emitchange) } }); } else { - Log::error << __PRETTY_FUNCTION__ << " Datadragon not set!"; + qCritical() << __PRETTY_FUNCTION__ << " Datadragon not set!"; } }