Skip to content

Commit

Permalink
Merge pull request #1007 from vktr/feature/console
Browse files Browse the repository at this point in the history
A filter console
  • Loading branch information
vktr committed Nov 12, 2020
2 parents a1966c8 + 510864d commit e61d343
Show file tree
Hide file tree
Showing 41 changed files with 2,069 additions and 154 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
[submodule "vendor/sentry-crashpad"]
path = vendor/sentry-crashpad
url = https://github.com/picotorrent/sentry-crashpad
[submodule "vendor/antlr4"]
path = vendor/antlr4
url = https://github.com/antlr/antlr4
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ if(DEFINED ENV{OPENSSL_ROOT_DIR})
message("Using OpenSSL dir from env variable: ${OPENSSL_ROOT_DIR}")
endif()

# --------- antlr4 options
option(WITH_STATIC_CRT "" Off)
# -----------------------

# --------- libtorrent options
option(BUILD_SHARED_LIBS "" off)
option(deprecated-functions "" off)
Expand All @@ -39,12 +43,16 @@ set(wxUSE_EXCEPTIONS OFF CACHE BOOL "" FORCE)

find_package(Boost REQUIRED COMPONENTS log)

# vendor libs
add_subdirectory(vendor/fmt)
add_subdirectory(vendor/libtorrent)
add_subdirectory(vendor/nlohmann-json)
add_subdirectory(vendor/sentry-crashpad)
add_subdirectory(vendor/wx)

# pico components
add_subdirectory(src/pql)

gitversion_install()
gitversion_showvariable(BranchName GITVERSION_VAR_BRANCHNAME)
gitversion_showvariable(MajorMinorPatch GITVERSION_VAR_VERSION)
Expand Down Expand Up @@ -165,6 +173,9 @@ add_executable(
src/picotorrent/ui/dialogs/preferenceslabelspage
src/picotorrent/ui/dialogs/preferencesproxypage

# Filters
src/picotorrent/ui/filters/pqltorrentfilter

# Models
src/picotorrent/ui/models/filestoragemodel
src/picotorrent/ui/models/peerlistmodel
Expand All @@ -175,6 +186,7 @@ add_executable(
src/picotorrent/ui/persistence/persistenttorrentlistview

# UI
src/picotorrent/ui/console
src/picotorrent/ui/mainframe
src/picotorrent/ui/statusbar
src/picotorrent/ui/taskbaricon
Expand Down Expand Up @@ -263,21 +275,15 @@ target_link_libraries(
# Rasterbar-libtorrent
"torrent-rasterbar"

# PQL
PicoTorrentPQL

sqlite
)

set_property(TARGET PicoTorrent PROPERTY ENABLE_EXPORTS 1)

# Plugins
add_library(
Plugin_Filters
SHARED
src/plugins/filters/filters
)

target_include_directories(Plugin_Filters PRIVATE include)
target_link_libraries(Plugin_Filters PRIVATE PicoTorrent)

add_library(
Plugin_Updater
SHARED
Expand Down
2 changes: 0 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Task("Build")
MSBuild(OutputDirectory + File("PicoTorrent.vcxproj"), settings);
// Plugins
MSBuild(OutputDirectory + File("Plugin_Filters.vcxproj"), settings);
MSBuild(OutputDirectory + File("Plugin_Updater.vcxproj"), settings);
});

Expand All @@ -83,7 +82,6 @@ Task("Setup-Publish-Directory")
MakeAbsolute(BuildDirectory + File("PicoTorrent.exe")),
MakeAbsolute(BuildDirectory + File("coredb.sqlite")),
MakeAbsolute(BuildDirectory + File("crashpad_handler.exe")),
MakeAbsolute(BuildDirectory + File("Plugin_Filters.dll")),
MakeAbsolute(BuildDirectory + File("Plugin_Updater.dll")),
};
Expand Down
1 change: 1 addition & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Rasterbar-libtorrent and wxWidgets.
configuration
creating-torrents
keyboard-shortcuts
pql
58 changes: 58 additions & 0 deletions docs/src/pql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
PQL - The PicoTorrent Query Language
====================================

PicoTorrent ships with an embedded query language which makes it possible to
filter the torrent list view in order to quickly show relevant information.

The query language (called PQL) is somewhat based on SQL but is designed to
make querying torrents easy.

For example, to query all torrents larger than 1GB, the following query can
be used;

.. code-block:: sql
size > 1gb
Examples
--------

- Torrents larger than 1gb that is currently downloading.
::

size > 1gb and status = "downloading"

- Torrents that are currently queued (either for downloading or uploading).
::

status = "queued"

- Torrents with either *1080p* or *720p* in the name.
::

name ~ "1080p" or name ~ "720p"


Fields
------

These are the fields available to query.

- :code:`name` (*string*) - the name of the torrent.
- :code:`progress` (*number*) - the current progress.
- :code:`size` (*number*) - the *total wanted* size - eg. total size excluding skipped files.
- :code:`status` (*string*) - the current status. Possible values are :code:`error`,
:code:`downloading`, :code:`paused`, :code:`queued`, :code:`seeding`, :code:`uploading`


Comparison operators
--------------------

- :code:`<` - less than.
- :code:`<=` - less than or equal.
- :code:`>` - greater than.
- :code:`>=` - greater than or equal.
- :code:`=` - equal.
- :code:`~` - like. Can be used to match part of torrent name to a string, For
example :code:`name ~ "ubuntu"` will match all torrents where the name contains
*ubuntu*.
2 changes: 0 additions & 2 deletions include/libpico.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ typedef struct libpico_torrent_stats_t
int32_t upload_payload_rate;
} libpico_torrent_stats_t;

typedef bool(*libpico_filter_callback_t)(libpico_torrent_t*, libpico_param_t*);
typedef libpico_result_t(*libpico_http_callback_t)(libpico_http_response_t*, libpico_http_status_t, libpico_param_t*);
typedef libpico_result_t(*libpico_init_t)(int, libpico_plugin_t*);
typedef libpico_result_t(*libpico_hook_callback_t)(libpico_event_t, libpico_param_t*, libpico_param_t*);
Expand All @@ -88,7 +87,6 @@ LIBPICO_API_FUNCTION libpico_result_t libpico_http_response_body_len(libpico_htt

LIBPICO_API_FUNCTION libpico_result_t libpico_i18n(const char* key, wchar_t* target, size_t* len);

LIBPICO_API_FUNCTION libpico_result_t libpico_mainwnd_filter_add(libpico_mainwnd_t* wnd, libpico_filter_callback_t cb, const wchar_t* name, libpico_param_t* user);
LIBPICO_API_FUNCTION libpico_result_t libpico_mainwnd_native_handle(libpico_mainwnd_t* wnd, void** handle);

/*
Expand Down
1 change: 1 addition & 0 deletions lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
"label_details": "Label details",
"color": "Color",
"apply_filter": "Apply filter",
"amp_console": "&Console",
"eta_hms_format": "{0}h {1}m {2}s",
"eta_ms_format": "{0}m {1}s",
"eta_s_format": "{0}s",
Expand Down
7 changes: 0 additions & 7 deletions packaging/WiX/PicoTorrent.Components.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@
Source="$(var.PublishDirectory)\crashpad_handler.exe" />
</Component>

<Component Id="C_Plugin_Filters.dll" Guid="88463251-e75a-4cfe-93b5-87c7170b5ebe">
<File Id="F_Plugin_Filters.dll"
KeyPath="yes"
Name="Plugin_Filters.dll"
Source="$(var.PublishDirectory)\Plugin_Filters.dll" />
</Component>

<Component Id="C_Plugin_Updater.dll" Guid="32b14933-0426-4e75-a115-56f2a9d21286">
<File Id="F_Plugin_Updater.dll"
KeyPath="yes"
Expand Down
2 changes: 2 additions & 0 deletions res/dbmigrations/20201015200912_insert_console_settings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO setting (key, value, default_value)
VALUES ('ui.show_console_input', NULL, 'false');
12 changes: 12 additions & 0 deletions res/dbmigrations/20201107234213_setup_filters.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
INSERT INTO setting (key, value, default_value)
VALUES ('current_filter', NULL, NULL);

CREATE TABLE filter (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
filter TEXT NOT NULL
);

INSERT INTO filter (name, filter) VALUES
('Downloading (active)', 'status = "downloading" and dl > 1kbps'),
('Uploading (active)', 'status = "uploading" and ul > 1kbps');
Binary file added res/terminal.ico
Binary file not shown.
14 changes: 0 additions & 14 deletions src/picotorrent/api/libpico.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,6 @@ libpico_result_t libpico_i18n(const char* key, wchar_t* target, size_t* len)
return libpico_ok;
}

libpico_result_t libpico_mainwnd_filter_add(libpico_mainwnd_t* wnd, libpico_filter_callback_t cb, const wchar_t* name, libpico_param_t* user)
{
reinterpret_cast<pt::UI::MainFrame*>(wnd)->AddFilter(
name,
[cb, user](pt::BitTorrent::TorrentHandle* torrent) -> bool
{
return cb(
reinterpret_cast<libpico_torrent_t*>(torrent),
user);
});

return libpico_ok;
}

libpico_result_t libpico_mainwnd_native_handle(libpico_mainwnd_t* wnd, void** handle)
{
*handle = reinterpret_cast<pt::UI::MainFrame*>(wnd)->GetHWND();
Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/bittorrent/torrenthandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void TorrentHandle::SetSequentialDownload(bool seq)
}
}

TorrentStatus TorrentHandle::Status()
TorrentStatus TorrentHandle::Status() const
{
return *m_status.get();
}
Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/bittorrent/torrenthandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace BitTorrent
bool IsValid();
void ReplaceTrackers(std::vector<libtorrent::announce_entry> const& trackers);
void ScrapeTracker(int trackerIndex);
TorrentStatus Status();
TorrentStatus Status() const;
std::vector<libtorrent::announce_entry> Trackers() const;

void ForceReannounce();
Expand Down
36 changes: 36 additions & 0 deletions src/picotorrent/core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,42 @@ std::vector<Configuration::DhtBootstrapNode> Configuration::GetDhtBootstrapNodes
return result;
}

std::vector<Configuration::Filter> Configuration::GetFilters()
{
std::vector<Filter> result;

auto stmt = m_db->CreateStatement("select id, name, filter from filter");

while (stmt->Read())
{
Filter f;
f.id = stmt->GetInt(0);
f.name= stmt->GetString(1);
f.filter = stmt->GetString(2);

result.push_back(f);
}

return result;
}

std::optional<Configuration::Filter> Configuration::GetFilterById(int id)
{
auto stmt = m_db->CreateStatement("select id, name, filter from filter where id = $1");
stmt->Bind(1, id);

if (stmt->Execute())
{
Filter f;
f.id = stmt->GetInt(0);
f.name = stmt->GetString(1);
f.filter = stmt->GetString(2);
return f;
}

return std::nullopt;
}

std::vector<Configuration::Label> Configuration::GetLabels()
{
std::vector<Label> result;
Expand Down
10 changes: 10 additions & 0 deletions src/picotorrent/core/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ namespace Core
int32_t port;
};

struct Filter
{
int32_t id;
std::string name;
std::string filter;
};

struct Label
{
Label() : id(-1), colorEnabled(false), savePathEnabled(false), applyFilterEnabled(false) {}
Expand Down Expand Up @@ -96,6 +103,9 @@ namespace Core

std::vector<DhtBootstrapNode> GetDhtBootstrapNodes();

std::vector<Filter> GetFilters();
std::optional<Filter> GetFilterById(int id);

// Labels
std::vector<Label> GetLabels();
void DeleteLabel(int32_t id);
Expand Down
5 changes: 5 additions & 0 deletions src/picotorrent/resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

AppIcon ICON "..\\..\\res\\app.ico"

// Icons
ICO_TERMINAL ICON "..\\..\\res\\terminal.ico"

// SQL migrations
20181208115043_create_setting_table DBMIGRATION "..\\..\\res\\dbmigrations\\20181208115043_create_setting_table.sql"
20181208115732_insert_default_settings DBMIGRATION "..\\..\\res\\dbmigrations\\20181208115732_insert_default_settings.sql"
Expand All @@ -21,7 +24,9 @@ AppIcon ICON "..\\..\\res\\app.ico"
20200916213321_insert_locale_name_setting DBMIGRATION "..\\..\\res\\dbmigrations\\20200916213321_insert_locale_name_setting.sql"
20200919221011_create_label_table DBMIGRATION "..\\..\\res\\dbmigrations\\20200919221011_create_label_table.sql"
20200925235912_save_resume_data_interval DBMIGRATION "..\\..\\res\\dbmigrations\\20200925235912_save_resume_data_interval.sql"
20201015200912_insert_console_settings DBMIGRATION "..\\..\\res\\dbmigrations\\20201015200912_insert_console_settings.sql"
20201027213145_insert_overview_columns DBMIGRATION "..\\..\\res\\dbmigrations\\20201027213145_insert_overview_columns.sql"
20201107234213_setup_filters DBMIGRATION "..\\..\\res\\dbmigrations\\20201107234213_setup_filters.sql"

VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILE_VERSION
Expand Down

0 comments on commit e61d343

Please sign in to comment.