Skip to content

Commit 6490b56

Browse files
Add options for repositories (uses alpm)
1 parent eb1581e commit 6490b56

File tree

8 files changed

+235
-117
lines changed

8 files changed

+235
-117
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ link_directories(${GTK3_LIBRARY_DIRS})
2525
# Add other flags to the compiler
2626
add_definitions(${GTK3_CFLAGS_OTHER})
2727

28+
# libalpm
29+
find_package(PkgConfig REQUIRED)
30+
pkg_check_modules(ALPM REQUIRED libalpm)
31+
2832
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
2933

3034
add_executable(pepv src/main.cpp src/pkgs.cpp src/utils.cpp src/events.cpp)
@@ -42,4 +46,4 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
4246
endif()
4347
endif()
4448

45-
target_link_libraries(pepv PRIVATE ${GTK3_LIBRARIES} Tracy::TracyClient)
49+
target_link_libraries(pepv PRIVATE ${GTK3_LIBRARIES} Tracy::TracyClient ${ALPM_LIBRARIES})

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* No uninstalling packages
1717
* No installing packages
1818
* No updating packages
19+
* Only support for `core`, `extra` and `multilib` repositories
1920

2021
## Why?
2122
* Because i want this program only to work as a viewer, everything regarding actually messing with your system should be in your own hands with you knowing what you are doing instead of me deciding what packages stay and go blindly

pepv.ui

Lines changed: 148 additions & 102 deletions
Large diffs are not rendered by default.

src/events.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ void populatePkgList() {
147147
static auto gShownSize = GTK_LABEL(gtk_builder_get_object(builder, "shownSize"));
148148
static auto gShownFiles = GTK_LABEL(gtk_builder_get_object(builder, "shownFiles"));
149149

150-
static auto gSourceOfficial = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "fromOfficial"));
151-
static auto gSourceAUR = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "fromAUR"));
150+
static auto gFromCore = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "fromCore"));
151+
static auto gFromExtra = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "fromExtra"));
152+
static auto gFromMultilib = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "fromMultilib"));
153+
static auto gFromAUR = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "fromAUR"));
152154

153155
const auto searchTerm = gtk_entry_get_text(GTK_ENTRY(gSearchEntry));
154156
const auto query = std::string_view(searchTerm);
@@ -158,8 +160,10 @@ void populatePkgList() {
158160
const auto typeExplicit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gTypeExplicit));
159161
const auto typeDependency = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gTypeDependency));
160162

161-
const auto fromOfficial = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSourceOfficial));
162-
const auto fromAUR = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSourceAUR));
163+
const auto fromCore = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gFromCore));
164+
const auto fromExtra = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gFromExtra));
165+
const auto fromMultilib = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gFromMultilib));
166+
const auto fromAUR = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gFromAUR));
163167

164168
const auto names = p->getPackagesNames();
165169

@@ -193,8 +197,10 @@ void populatePkgList() {
193197
totalSize += pkg.size.value_or(0);
194198
totalFiles += files;
195199

196-
if (!fromOfficial && !pkg.isLocal) continue;
197-
if (!fromAUR && pkg.isLocal) continue;
200+
if (pkg.repo.has_value() && pkg.repo.value() == DBS_CORE && !fromCore) continue;
201+
if (pkg.repo.has_value() && pkg.repo.value() == DBS_EXTRA && !fromExtra) continue;
202+
if (pkg.repo.has_value() && pkg.repo.value() == DBS_MULTILIB && !fromMultilib) continue;
203+
if (!pkg.repo.has_value() && !fromAUR) continue;
198204

199205
if (pkg.reason == REASON_EXPLICIT && !typeExplicit) continue;
200206
if (pkg.reason == REASON_DEPEND && !typeDependency) continue;
@@ -214,6 +220,8 @@ void populatePkgList() {
214220
const auto numDeps = pkg.depends.size();
215221
const auto desc = pkg.desc.value_or("");
216222

223+
std::string_view repo = repoIdToStr(pkg.repo.value_or((REPOS)-1));
224+
217225
gtk_tree_store_append(treeStore, &iter, NULL);
218226

219227
gtk_tree_store_set(treeStore, &iter,
@@ -223,7 +231,9 @@ void populatePkgList() {
223231
COL_LIST_NUM_DEPS, numDeps,
224232
COL_LIST_DESC, desc.c_str(),
225233
COL_LIST_SIZE, pkg.size.value_or(0),
226-
COL_LIST_FILES, files, -1);
234+
COL_LIST_FILES, files,
235+
COL_LIST_REPO, repo.data(),
236+
-1);
227237
shownCount++;
228238
shownSize += pkg.size.value_or(0);
229239
shownFiles += files;

src/pkgs.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <cstdio>
44
#include <iostream>
55

6+
#include <alpm.h>
7+
#include <alpm_list.h>
8+
9+
#include <string_view>
610
#include <tracy/Tracy.hpp>
711

812
void Pkgs::init() {
@@ -27,6 +31,19 @@ void Pkgs::initDescriptions() {
2731
ZoneScopedN("Pkgs::initDescriptions()");
2832
if (!inited) return;
2933

34+
std::map<REPOS, alpm_db_t*> repos;
35+
36+
{
37+
ZoneNamedN(___tracy_pkg_pacman, "Initialize alpm and dbs", true);
38+
alpm_errno_t alpmErr = ALPM_ERR_OK;
39+
auto handle = alpm_initialize("/", "/var/lib/pacman/", nullptr);
40+
41+
for (auto [repoId, repoName] : Repositories) {
42+
alpm_db_t* db = alpm_register_syncdb(handle, repoName.data(), ALPM_DB_USAGE_SEARCH);
43+
repos.emplace(repoId, db);
44+
}
45+
}
46+
3047
std::set<fs::path> tempPkgsPaths;
3148
{
3249
ZoneNamedN(___tracy_pkg_paths, "get package paths", true);
@@ -122,8 +139,6 @@ void Pkgs::initDescriptions() {
122139
}
123140
case SECTION_DESC_PACKAGER:
124141
pkg.packager.emplace(currentLine);
125-
if (currentLine == "Unknown Packager")
126-
pkg.isLocal = true; // TODO: is this correct?
127142
break;
128143
case SECTION_DESC_SIZE: {
129144
auto num = std::stoull(currentLine.data());
@@ -169,6 +184,18 @@ void Pkgs::initDescriptions() {
169184
}
170185
}
171186
fclose(f);
187+
188+
{
189+
ZoneNamedN(___tracy_pkg_pacman, "Initialize alpm and dbs", true);
190+
for (auto [repoId, db] : repos) {
191+
auto pkgFound = alpm_db_get_pkg(db, pkg.name.c_str());
192+
if (pkgFound) {
193+
pkg.repo.emplace(repoId);
194+
break;
195+
}
196+
}
197+
}
198+
172199
pkgPaths.insert({pkg.name, path});
173200
descriptions.insert({pkg.name, pkg});
174201
}

src/pkgs.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <set>
55
#include <optional>
66
#include <filesystem>
7+
#include <string_view>
78

89
namespace fs = std::filesystem;
910

@@ -15,13 +16,26 @@ enum LIST_COLS {
1516
COL_LIST_DESC,
1617
COL_LIST_SIZE,
1718
COL_LIST_FILES,
19+
COL_LIST_REPO,
1820
};
1921

2022
enum BACKUP_COLS {
2123
COL_BACKUP_PATH = 0,
2224
COL_BACKUP_HASH,
2325
};
2426

27+
enum REPOS : uint8_t {
28+
DBS_CORE,
29+
DBS_EXTRA,
30+
DBS_MULTILIB,
31+
};
32+
33+
const std::map<REPOS, std::string_view> Repositories = {
34+
{DBS_CORE, "core"},
35+
{DBS_EXTRA, "extra"},
36+
{DBS_MULTILIB, "multilib"},
37+
};
38+
2539
enum SectionDesc {
2640
SECTION_DESC_NONE,
2741
SECTION_DESC_NAME,
@@ -81,7 +95,7 @@ struct PackageDescription {
8195
std::optional<std::string> xdata;
8296
std::set<std::string> requiredBy;
8397
std::set<std::string> optRequiredBy;
84-
bool isLocal = false; // AUR / self-packaged
98+
std::optional<REPOS> repo;
8599
};
86100

87101
class Pkgs {

src/utils.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "utils.hpp"
2+
#include "pkgs.hpp"
23

34
#include <cmath>
45

6+
#include <string_view>
57
#include <tracy/Tracy.hpp>
68

79
std::string formattedTimestamp(const time_t t) {
@@ -21,9 +23,22 @@ std::string_view reasonToStr(PKGReason r) {
2123
return reasonStr;
2224
}
2325

26+
std::string_view repoIdToStr(REPOS repo) {
27+
std::string_view repoStr = "Undefined";
28+
switch (repo) {
29+
case DBS_CORE: repoStr = "core"; break;
30+
case DBS_EXTRA: repoStr = "extra"; break;
31+
case DBS_MULTILIB: repoStr = "multilib"; break;
32+
default:
33+
repoStr = "AUR";
34+
break;
35+
}
36+
return repoStr;
37+
}
38+
2439
std::string formattedSize(const uint64_t s, bool binary) {
25-
const int divider = binary ? 1024 : 1000;
26-
const std::string_view byteIndicator = binary ? "iB" : "B";
40+
const int divider = binary ? 1024 : 1000;
41+
const std::string_view byteIndicator = binary ? "iB" : "B";
2742
std::stringstream ss;
2843
if (s < divider) {
2944
ss << s << " Bytes";
@@ -42,8 +57,8 @@ std::string formattedSize(const uint64_t s, bool binary) {
4257
std::string setToStr(std::set<std::string> s, const char* delimeter) {
4358
ZoneScopedN("setToStr");
4459
std::stringstream ss;
45-
int i = 0;
46-
int size = s.size();
60+
int i = 0;
61+
int size = s.size();
4762
for (const auto& str : s) {
4863
i++;
4964
if (i == size)

src/utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern Pkgs* p;
55

66
std::string formattedTimestamp(const time_t t);
77
std::string_view reasonToStr(PKGReason r);
8+
std::string_view repoIdToStr(REPOS repo);
89
std::string formattedSize(const uint64_t s, bool binary = false);
910
std::string setToStr(std::set<std::string> s, const char* delimeter = " ");
1011
std::string optDependsToStr(std::set<std::string> s);

0 commit comments

Comments
 (0)