commit 6fd4eb971184ceb36e1c2cb027bc04f0c79a0a26
parent f7b0a3fb7a7f0667a0520fa1a15260a5f586f15a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 16 Mar 2016 18:24:01 -0400
display the install status of each pacakge
Diffstat:
2 files changed, 121 insertions(+), 25 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -18,8 +18,8 @@
#include "browser.hpp"
#include "encoding.hpp"
+#include "errors.hpp"
#include "index.hpp"
-#include "listview.hpp"
#include "reapack.hpp"
#include "resource.hpp"
@@ -58,7 +58,7 @@ void Browser::onInit()
m_list->sortByColumn(1);
reload();
- m_reloadTimer = startTimer(200);
+ m_filterTimer = startTimer(200);
}
void Browser::onCommand(const int id)
@@ -67,7 +67,7 @@ void Browser::onCommand(const int id)
case IDC_SCRIPTS:
case IDC_EFFECTS:
case IDC_EXTENSIONS:
- reload();
+ fillList();
break;
case IDC_FILTER:
m_checkFilter = true;
@@ -90,14 +90,15 @@ void Browser::onContextMenu(HWND, const int, const int)
void Browser::onTimer(const int id)
{
- if(id != m_reloadTimer || !m_checkFilter)
- return;
-
- checkFilter();
+ if(id == m_filterTimer)
+ checkFilter();
}
void Browser::checkFilter()
{
+ if(!m_checkFilter)
+ return;
+
m_checkFilter = false;
auto_string wideFilter(4096, 0);
@@ -108,44 +109,121 @@ void Browser::checkFilter()
if(filter != m_filter) {
m_filter = filter;
- reload();
+ fillList();
}
}
void Browser::reload()
{
+ try {
+ Registry reg(Path::prefixRoot(Path::REGISTRY));
+
+ m_entries.clear();
+
+ for(IndexPtr index : m_indexes) {
+ for(const Package *pkg : index->packages())
+ m_entries.push_back({pkg->lastVersion(), reg.getEntry(pkg)});
+ }
+
+ fillList();
+ }
+ catch(const reapack_error &e) {
+ const auto_string &desc = make_autostring(e.what());
+ auto_char msg[255] = {};
+ auto_snprintf(msg, sizeof(msg),
+ AUTO_STR("ReaPack could not open the package registry.\r\n")
+ AUTO_STR("Retry later when all installation task are completed.\r\n")
+ AUTO_STR("\r\nError description: %s"),
+ desc.c_str());
+ MessageBox(handle(), msg, AUTO_STR("ReaPack"), MB_OK);
+ }
+}
+
+void Browser::fillList()
+{
InhibitControl freeze(m_list);
m_list->clear();
- for(IndexPtr index : m_indexes) {
- for(const Package *pkg : index->packages()) {
- const Version *ver = pkg->lastVersion();
+ for(const Entry &entry : m_entries) {
+ if(match(entry))
+ m_list->addRow(makeRow(entry));
+ }
- if(!match(ver))
- continue;
+ m_list->sort();
+}
- m_list->addRow({"??", pkg->name(), pkg->category()->name(),
- ver->name(), ver->displayAuthor(), pkg->displayType()});
+ListView::Row Browser::makeRow(const Entry &entry) const
+{
+ const string &state = getValue(StateColumn, entry);
+ const string &name = getValue(NameColumn, entry);
+ const string &category = getValue(CategoryColumn, entry);
+ const string &version = getValue(VersionColumn, entry);
+ const string &author = getValue(AuthorColumn, entry);
+ const string &type = getValue(TypeColumn, entry);
+
+ return {
+ make_autostring(state), make_autostring(name), make_autostring(category),
+ make_autostring(version), make_autostring(author), make_autostring(type)
+ };
+}
+
+string Browser::getValue(const Column col, const Entry &entry) const
+{
+ const Version *ver = entry.version;
+ const Package *pkg = ver ? ver->package() : nullptr;
+ const Registry::Entry ®Entry = entry.regEntry;
+
+ string display;
+
+ switch(col) {
+ case StateColumn:
+ if(regEntry.id)
+ display += ver ? 'i' : 'o';
+ else
+ display += '\x20';
+
+ return display;
+ case NameColumn:
+ return pkg ? pkg->name() : regEntry.package;
+ case CategoryColumn:
+ return pkg ? pkg->category()->name() : regEntry.category;
+ case VersionColumn:
+ if(regEntry.id)
+ display = regEntry.versionName;
+
+ if(ver && ver->code() != regEntry.versionCode) {
+ if(!display.empty())
+ display += "\x20";
+
+ display += "(" + ver->name() + ")";
}
- }
- m_list->sort();
+ return display;
+ case AuthorColumn:
+ return ver ? ver->displayAuthor() : "";
+ case TypeColumn:
+ return pkg ? pkg->displayType() : Package::displayType(regEntry.type);
+ }
}
-bool Browser::match(const Version *ver)
+bool Browser::match(const Entry &entry) const
{
using namespace boost;
- const Package *pkg = ver->package();
+ const Package::Type type =
+ entry.version ? entry.version->package()->type() : entry.regEntry.type;
- const auto typeIt = m_types.find(pkg->type());
+ const auto typeIt = m_types.find(type);
if(typeIt == m_types.end() ||
SendMessage(typeIt->second, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
return false;
- return icontains(pkg->name(), m_filter) ||
- icontains(pkg->category()->name(), m_filter) ||
- icontains(ver->author(), m_filter);
+ const string &name = getValue(NameColumn, entry);
+ const string &category = getValue(CategoryColumn, entry);
+ const string &author = getValue(AuthorColumn, entry);
+
+ return icontains(name, m_filter) || icontains(category, m_filter) ||
+ icontains(author, m_filter);
}
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -20,6 +20,9 @@
#include "dialog.hpp"
+#include "listview.hpp"
+#include "registry.hpp"
+
#include <map>
#include <memory>
#include <string>
@@ -44,14 +47,29 @@ protected:
void onTimer(int) override;
private:
- bool match(const Version *);
+ struct Entry { const Version *version; Registry::Entry regEntry; };
+
+ enum Column {
+ StateColumn,
+ NameColumn,
+ CategoryColumn,
+ VersionColumn,
+ AuthorColumn,
+ TypeColumn,
+ };
+
+ bool match(const Entry &) const;
void checkFilter();
+ void fillList();
+ std::string getValue(Column, const Entry &entry) const;
+ ListView::Row makeRow(const Entry &) const;
std::vector<IndexPtr> m_indexes;
ReaPack *m_reapack;
bool m_checkFilter;
- int m_reloadTimer;
+ int m_filterTimer;
std::string m_filter;
+ std::vector<Entry> m_entries;
HWND m_filterHandle;
std::map<int, HWND> m_types;