-
Notifications
You must be signed in to change notification settings - Fork 0
/
NOTES.txt
583 lines (467 loc) · 18.7 KB
/
NOTES.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
Todos to check in qBittorent torrentexporter:
---------------------------------------------
- set setForwardOnly(true) for all queries for better performance
- solve explicit, default and delete for contructors, use this keywords correctly
- use every where toNativePath()
- rewrite all to range-based for loop
Todos to check in qMedia:
-------------------------
- QHash::operator[] returns default when value not exists and silently inserts that item into the hash, check all code usage 😠
C preprocessor macros:
----------------------
- LOG_CHANGED_TORRENTS - log debug messages about changed torrents, messages are logged every second
- LOG_GEOMETRY - debug geometry changes, like resize and show/hide columns during qBittorent up/down
- VISIBLE_CONSOLE - set up smaller, so I can see console output in the QtCreator, but only at initial
questions:
----------
- laravel Grammar/Grammar::whereBasic()
- $operator = str_replace('?', '??', $where['operator']);
Example code which heavily uses win32 api:
------------------------------------------
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM)
{
// For reference, very important:
// https://docs.microsoft.com/en-us/archive/msdn-magazine/2015/july/c-using-stl-strings-at-win32-api-boundaries
const int windowTextLength = ::GetWindowTextLength(hwnd) + 1;
auto windowText = std::make_unique<wchar_t[]>(windowTextLength);
// std::vector<wchar_t> windowText(windowTextLength);
// std::wstring windowText;
// windowText.resize(windowTextLength);
::GetWindowText(hwnd, windowText.get(), windowTextLength);
// ::GetWindowText(hwnd, const_cast<wchar_t *>(windowText.c_str()), windowTextLength);
std::wstring text(windowText.get());
// windowText.resize(windowTextLength - 1);
if (::wcsstr(windowText.get(), L"qBittorrent"))
qDebug() << "xx";
// Example: [D: 0 B/s, U: 1,3 MiB/s] qBittorrent v4.2.5
const std::wregex re(L"^(\\[\\D: .*\\, U\\: .*\\] )?qBittorrent (v\\d+\\.\\d+\\.\\d+([a-zA-Z]+\\d{0,2})?)$");
if (!std::regex_match(windowText.get(), re))
// if (::!wcsstr(windowText.get(), L"qBittorrent"))
return true;
// wchar_t className[MAX_PATH];
// ::GetClassName(hwnd, className, ARRAYSIZE(className));
// if (!::wcscmp(className, L"Qt5QWindowIcon") != 0)
// return true;
DWORD pid;
::GetWindowThreadProcessId(hwnd, &pid);
const HANDLE processHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid);
if (processHandle == NULL) {
qDebug() << "OpenProcess() in EnumWindows() failed : " << ::GetLastError();
return true;
}
wchar_t moduleFilePath[MAX_PATH];
::GetModuleFileNameEx(processHandle, NULL, moduleFilePath, ARRAYSIZE(moduleFilePath));
// More instances of qBittorrent can run, so find proper one
#ifdef QT_DEBUG
// String has to start with moduleFileName
if (::wcsstr(moduleFilePath, L"E:\\c\\qbittorrent_64-dev\\qBittorrent\\qBittorrent-builds")
!= &moduleFilePath[0])
return true;
#else
if (::wcsstr(moduleFileName, L"C:\\Program Files\\qBittorrent") != &moduleFileName[0])
return true;
#endif
// ::PathStripPath(moduleFileName);
const QString moduleFileName = Utils::Fs::fileName(QString::fromWCharArray(moduleFilePath));
::CloseHandle(processHandle);
if (moduleFileName == "qbittorrent.exe")
// if (::wcscmp(moduleFilePath, L"qbittorrent.exe") != 0)
return true;
qDebug() << "HWND for qBittorrent window found : " << hwnd;
l_mainWindow->setQBittorrentHwnd(hwnd);
return false;
}
QProgressBar in qTableView:
---------------------------
// QProxyStyle fusionStyle {"windowsvista"};
painter->save();
// QPalette p = newopt.palette;
// p.setColor(QPalette::Window, QColor(0, 0, 0, 0));
// newopt.palette = p;
// Draw progressbar without border / groove
style->drawControl(QStyle::CE_ProgressBarContents, &newopt, painter);
style->drawControl(QStyle::CE_ProgressBarLabel, &newopt, painter);
// style->drawControl(QStyle::CE_ProgressBarGroove, &newopt, painter);
// style->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
painter->restore();
WM_COPYDATA torrent ids as std::vector<quint64>:
------------------------------------------------
const COPYDATASTRUCT copyData = *reinterpret_cast<PCOPYDATASTRUCT>(msg->lParam);
switch (static_cast<int>(msg->wParam)) {
case MSG_QBT_TORRENTS_CHANGED:
// Put together std::vector of torrentId
const int dataSize = static_cast<int>(copyData.cbData);
const quint64 *const begin = static_cast<const quint64 *>(copyData.lpData);
const quint64 *const end = begin + (dataSize / sizeof(quint64));
const std::vector<quint64> torrentIds(begin, end);
qDebug() << "IPC qBittorrent : Changed torrents copyData size :" << dataSize;
qDebug() << "IPC qBittorrent : Changed torrents ids :" << torrentIds;
emit m_mainWindow->torrentsChanged(torrentIds);
return true;
}
Directly update model:
----------------------
QModelIndexList selectedIndexes = ui->tableView->selectionModel()->selectedRows(1);
if (selectedIndexes.isEmpty())
return;
QModelIndex selectedIndex = selectedIndexes.first();
if (!selectedIndex.isValid())
return;
m_model->setData(m_proxyModel->mapToSource(selectedIndex), "ahoj");
Performance measure timer:
--------------------------
#include <QElapsedTimer>
QElapsedTimer timer;
timer.start();
qDebug().noquote() << QStringLiteral("Elapsed in XX : %1ms").arg(timer.elapsed());
Dark theme by Windows settings:
-------------------------------
#include <QSettings>
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\"
"Themes\\Personalize",
QSettings::NativeFormat);
if (settings.value("AppsUseLightTheme") == 0) {
}
imdb movie detail:
------------------
class AbstractMovieDetailService:
signals:
void searchPageFetched();
void movieDetailPageFetched();
protected:
virtual QString getMovieDetailUrl(QString searchPage) = 0;
QString prepareSearchQueryString(const QSqlRecord &torrent) const;
MovieDetail m_movieDetail;
QHash<quint64, MovieDetail> m_movieDetailsCache;
private:
enum CurrentlyProcessing
{
PROCESSING_NOTHING,
PROCESSING_SEARCH_PAGE,
PROESSING_MOVIE_DETAIL_PAGE,
};
MovieDetail selectMovieDetailByTorrentId(quint64 id);
void fetchPageByUrl(QString searchQuery);
void fetchPageFinished(QNetworkReply *reply);
void insertMovieDetailToDb(const MovieDetail &movieDetail);
QString m_searchPage;
QString m_movieDetailPage;
int m_currentlyProcessing = PROCESSING_NOTHING;
QNetworkAccessManager m_networkManager;
was in AbstractMovieDetailService::getMovieDetail():
// Fetch movie detail from internet
// {
// QString searchQuery = prepareSearchQueryString(torrent);
// m_currentlyProcessing = PROCESSING_SEARCH_PAGE;
// fetchPageByUrl(searchQuery);
// QEventLoop eventLoop;
// eventLoop.connect(this, &AbstractMovieDetailService::searchPageFetched, &eventLoop, &QEventLoop::quit);
// eventLoop.exec();
// }
// {
// QString movieDetailUrl = getMovieDetailUrl(m_searchPage);
// m_currentlyProcessing = PROESSING_MOVIE_DETAIL_PAGE;
// fetchPageByUrl(movieDetailUrl);
// QEventLoop eventLoop1;
// eventLoop1.connect(this, &AbstractMovieDetailService::movieDetailPageFetched, &eventLoop1, &QEventLoop::quit);
// eventLoop1.exec();
// }
AbstractMovieDetailService::AbstractMovieDetailService(QObject *parent)
: QObject(parent)
{
//
connect(&m_networkManager, &QNetworkAccessManager::finished, this, &AbstractMovieDetailService::fetchPageFinished);
}
void AbstractMovieDetailService::fetchPageByUrl(QString searchQuery)
{
// TODO error handling silverqx
QString searchUrlString = "https://www.csfd.cz/hledat/?q=" + searchQuery;
m_networkManager.get(QNetworkRequest(QUrl(searchUrlString)));
}
void AbstractMovieDetailService::fetchPageFinished(QNetworkReply *reply)
{
QString pageContent = QString::fromStdString(reply->readAll().toStdString());
switch (m_currentlyProcessing) {
case PROCESSING_SEARCH_PAGE:
m_searchPage = pageContent;
emit searchPageFetched();
break;
case PROESSING_MOVIE_DETAIL_PAGE:
m_movieDetailPage = pageContent;
emit movieDetailPageFetched();
break;
}
}
was in CsfdMovieDetail:
QString getMovieDetailUrl(QString searchPage) override;
csfd-api movie scrapper:
------------------------
missing:
- SE special edition length ( eg. aliens movie )
- kamera ( aliens )
- pracovní název for titles ( How to Train Your Dragon 3 )
app colors:
-----------
// Blue
// darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
// Blue
// darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
// darkPalette.setColor(QPalette::HighlightedText, Qt::black);
// Dark pastel green
// darkPalette.setColor(QPalette::Highlight, QColor(29, 84, 92));
// darkPalette.setColor(QPalette::HighlightedText, textColor);
// Dark orange
// darkPalette.setColor(QPalette::Highlight, QColor(255, 139, 0));
// darkPalette.setColor(QPalette::HighlightedText, textColor);
detect resize event ended:
--------------------------
https://stackoverflow.com/questions/7753795/qt-user-resize-event-ends-stops
decoration position for QStyledItemDelegate:
--------------------------------------------
code is from QStyledItemDelegate::initStyleOption()
QSize actualSize = option->icon.actualSize(option->decorationSize, mode, state);
// For highdpi icons actualSize might be larger than decorationSize, which we don't want. Clamp it to decorationSize.
option->decorationSize = QSize(qMin(option->decorationSize.width(), actualSize.width()),
qMin(option->decorationSize.height(), actualSize.height()));
Merge torrents' changed properties:
-----------------------------------
torrentexporter.h:
--
class TorrentExporter final : public QObject
private:
struct ChangedPropertiesStore
{
TorrentsChangedHash torrents;
TorrentsFilesChangedHash torrentsFiles;
inline bool isEmpty() const
{
if (torrents.isEmpty() && torrentsFiles.isEmpty())
return true;
return false;
}
inline void clear()
{
torrents.clear();
torrentsFiles.clear();
}
} m_changedPropertiesStore;
void mergeTorrentChangedProperties(const TorrentId torrentId,
const QSharedPointer<TorrentChangedProperties> &torrentsChangedProperties);
void mergeTorrentFilesChangedProperties(
const TorrentId torrentId,
const QSharedPointer<TorrentFilesChangedHash> &filesChangedProperties);
void mergeChangedProperties(
const QSharedPointer<QVariantHash> &propertiesStore,
const QSharedPointer<const QVariantHash> &changedProperties);
torrentexporter.cpp:
--
void TorrentExporter::mergeTorrentChangedProperties(
const TorrentId torrentId,
const QSharedPointer<TorrentChangedProperties> &changedProperties)
{
auto &torrentsStore = m_changedPropertiesStore.torrents;
// If this torrent's changed properties aren't in the store, simply insert them
if (!torrentsStore.contains(torrentId)) {
torrentsStore.insert(torrentId, changedProperties);
return;
}
// Process/Merge changed properties
mergeChangedProperties(torrentsStore[torrentId], changedProperties);
}
void TorrentExporter::mergeTorrentFilesChangedProperties(
const TorrentId torrentId,
const QSharedPointer<TorrentFilesChangedHash> &filesChangedProperties)
{
auto &torrentsFilesStore = m_changedPropertiesStore.torrentsFiles;
// If these torrent files changed properties are not in the store, simply insert them
if (!torrentsFilesStore.contains(torrentId)) {
torrentsFilesStore.insert(torrentId, filesChangedProperties);
return;
}
// Iterate over a changed files
auto itFiles = filesChangedProperties->constBegin();
while (itFiles != filesChangedProperties->constEnd())
{
const auto fileId = itFiles.key();
const auto changedFileProperties = itFiles.value();
++itFiles;
auto &changedFilesStore = torrentsFilesStore[torrentId];
// If this torrent file is not in the store, simply insert it
if (!changedFilesStore->contains(fileId)) {
changedFilesStore->insert(fileId, changedFileProperties);
continue;
}
// Process/Merge changed file properties
mergeChangedProperties((*changedFilesStore)[fileId], changedFileProperties);
}
}
void TorrentExporter::mergeChangedProperties(
const QSharedPointer<QVariantHash> &propertiesStore,
const QSharedPointer<const QVariantHash> &changedProperties)
{
// Process/Merge changed properties
auto itTorrent = changedProperties->constBegin();
while (itTorrent != changedProperties->constEnd())
{
const auto property = itTorrent.key();
const auto value = itTorrent.value();
++itTorrent;
// Torrent property value is the same, can be skipped
if (propertiesStore->value(property) == value)
continue;
// Insert new or overwrite the old one
propertiesStore->insert(property, value);
}
}
qBittorrent deduce return type:
-------------------------------
template <typename T>
struct return_type;
template <typename R, typename... Args>
struct return_type<R(*)(Args...)> { using type = R; };
template <typename R, typename C, typename... Args>
struct return_type<R(C::*)(Args...)> { using type = R; };
template <typename R, typename C, typename... Args>
struct return_type<R(C::*)(Args...) const> { using type = R; };
template <typename R, typename C, typename... Args>
struct return_type<R(C::*)(Args...) volatile> { using type = R; };
template <typename R, typename C, typename... Args>
struct return_type<R(C::*)(Args...) const volatile> { using type = R; };
template <typename T>
using return_type_t = typename return_type<T>::type;
header:
--
class BaseRepository
template<typename P>
Export::return_type_t<decltype (&P::present)>
presentResult(QSqlQuery &query);
source:
--
template<typename P>
Export::return_type_t<decltype (&P::present)>
BaseRepository::presentResult(QSqlQuery &query)
{
return P().present(query);
}
presenters test code:
--
const auto hash = static_cast<QString>(torrents.first()->hash());
const auto torrentId =
m_torrentsRepository.findWhere<Presenter::FirstId>({{"hash", hash}},
{{"id"}});
if (torrentId)
;
const auto torrentId1 =
m_torrentsRepository.findWhere({{"hash", hash}},
{{"id"}});
// QStringList ll;
// ll << "id" << "hash";
auto vv = m_torrentsRepository.findWhereIn<Presenter::TorrentIdByInfoHash, TorrentId>(
"id",
{{269, 268, 267}});
qDebug() << "vv :" << vv;
auto [zzok, zzquery] = m_torrentsRepository.findWhereIn<void, TorrentId>(
"id",
{{269, 268, 267}});
qDebug() << "zzok :" << zzok;
qt_noop();
presenters with data test code ✨🚀, wtf 😂💪:
--
QHash<BitTorrent::InfoHash, QString> data {
{BitTorrent::InfoHash("6948503d484853cc6380374268daac161d4139cb"), QString("dvasestdevet")},
{BitTorrent::InfoHash("bf9661defa3daecacfde5bde0214c4a439351d4d"), QString("jedna")},
{BitTorrent::InfoHash("d3fc13dc12d8d7a58e7ae87295e93dbaddb5d36b"), QString("pjet")},
};
auto xx = m_torrentsRepository.findWhere<Presenter::TorrentHandleByInfoHashData>(
{{"id", 269, "=", "OR"}, {"id", 5, "=", "OR"}, {"id", 1, "="}},
data, {"id", "hash"});
qDebug() << "xx :" << xx;
auto yy = m_torrentsRepository.findWhereIn<Presenter::TorrentHandleByInfoHashData, quint64>(
"id", {269, 1, 5},
data, {"id", "hash"});
qDebug() << "yy :" << yy;
prepareWhere() test code:
--
BaseRepository::BaseRepository(EntityManager &em)
: m_em(em)
{
auto xx = prepareWhereClause({
{"name", "peto"},
{"name", "andrej", "<>"},
{"index", 10}
});
auto yy = prepareWhereCondClause({
{"name", "peto"},
{"name", "andrej", "<>", "OR"},
{"index", 10, "=", ""}
});
qDebug() << "xx :" << xx;
qDebug() << "yy :" << yy;
qt_noop();
}
Prototype store:
----------------
- I no longer remember how this was intended.
struct StoreItem
{
std::function<void()> service;
StoreItem(std::function<void()> service_)
: service(service_)
{}
};
struct StoreItemHandle : public StoreItem
{
BitTorrent::TorrentHandle *const torrent;
StoreItemHandle(std::function<void()> service_, BitTorrent::TorrentHandle *const torrent_)
: StoreItem(service_)
, torrent(torrent_)
{}
};
struct StoreItemHash final : public StoreItem
{
BitTorrent::InfoHash infoHash;
};
struct StoreItemPath final : public StoreItemHandle
{
QString newPath;
};
QQueue<StoreItem> m_changedPropertiesStore;
constructor copy/move snippet:
------------------------------
Torrent(const Torrent &torrent)
: BaseModel(torrent)
{
qDebug() << "Torrent copy ctor";
}
Torrent &operator=(const Torrent &torrent)
{
BaseModel::operator=(torrent);
qDebug() << "Torrent copy assign";
return *this;
}
Torrent(Torrent &&torrent)
: BaseModel(std::move(torrent))
{
qDebug() << "Torrent move ctor";
}
Torrent &operator=(Torrent &&torrent)
{
BaseModel::operator=(std::move(torrent));
qDebug() << "Torrent move assign";
return *this;
}
conversions:
------------
Makes possible to assign QVector<AttributeItem> to the Model,
or implicitly converts a QVector<AttributeItem> to Model:
BaseModel(const QVector<AttributeItem> &attributes);
BaseModel(QVector<AttributeItem> &&attributes);
--
Allows initialize the Model with QVector<AttributeItem>:
BaseModel(std::initializer_list<AttributeItem> attributes)
: BaseModel(QVector<AttributeItem> {attributes.begin(), attributes.end()})
{}
--
Makes possible to assign the Model to the QVector<AttributeItem>,
or converts the Model to the QVector<AttributeItem>:
operator QVector<AttributeItem>() const;