Don't show full path on Data Recover view if the user wants to hide them

This commit is contained in:
David Capello 2019-05-31 09:42:08 -03:00
parent 93fe19d353
commit 1ac3148f72
4 changed files with 56 additions and 15 deletions

View File

@ -30,6 +30,7 @@
#include "base/thread.h" #include "base/thread.h"
#include "base/time.h" #include "base/time.h"
#include "doc/cancel_io.h" #include "doc/cancel_io.h"
#include "fmt/format.h"
namespace app { namespace app {
namespace crash { namespace crash {
@ -44,16 +45,23 @@ Session::Backup::Backup(const std::string& dir)
DocumentInfo info; DocumentInfo info;
read_document_info(dir, info); read_document_info(dir, info);
std::vector<char> buf(1024); m_fn = info.filename;
sprintf(&buf[0], "%s Sprite %dx%d, %d %s: %s", m_desc =
info.mode == ColorMode::RGB ? "RGB": fmt::format("{} Sprite {}x{}, {} {}",
info.mode == ColorMode::GRAYSCALE ? "Grayscale": info.mode == ColorMode::RGB ? "RGB":
info.mode == ColorMode::INDEXED ? "Indexed": info.mode == ColorMode::GRAYSCALE ? "Grayscale":
info.mode == ColorMode::BITMAP ? "Bitmap": "Unknown", info.mode == ColorMode::INDEXED ? "Indexed":
info.width, info.height, info.frames, info.mode == ColorMode::BITMAP ? "Bitmap": "Unknown",
info.frames == 1 ? "frame": "frames", info.width, info.height, info.frames,
info.filename.c_str()); info.frames == 1 ? "frame": "frames");
m_desc = &buf[0]; }
std::string Session::Backup::description(const bool withFullPath) const
{
return fmt::format("{}: {}",
m_desc,
withFullPath ? m_fn:
base::get_file_name(m_fn));
} }
Session::Session(RecoveryConfig* config, Session::Session(RecoveryConfig* config,

View File

@ -32,10 +32,11 @@ namespace crash {
public: public:
Backup(const std::string& dir); Backup(const std::string& dir);
const std::string& dir() const { return m_dir; } const std::string& dir() const { return m_dir; }
const std::string& description() const { return m_desc; } std::string description(const bool withFullPath) const;
private: private:
std::string m_dir; std::string m_dir;
std::string m_desc; std::string m_desc;
std::string m_fn;
}; };
typedef std::vector<Backup*> Backups; typedef std::vector<Backup*> Backups;

View File

@ -17,6 +17,7 @@
#include "app/crash/session.h" #include "app/crash/session.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/task.h" #include "app/task.h"
#include "app/ui/data_recovery_view.h" #include "app/ui/data_recovery_view.h"
#include "app/ui/drop_down_button.h" #include "app/ui/drop_down_button.h"
@ -52,11 +53,10 @@ namespace {
class Item : public ListItem { class Item : public ListItem {
public: public:
Item(crash::Session* session, crash::Session::Backup* backup) Item(crash::Session* session, crash::Session::Backup* backup)
: ListItem(backup->description()) : m_session(session)
, m_session(session)
, m_backup(backup) , m_backup(backup)
, m_task(nullptr) , m_task(nullptr) {
{ updateText();
} }
crash::Session* session() const { return m_session; } crash::Session* session() const { return m_session; }
@ -122,6 +122,13 @@ public:
updateView(); updateView();
} }
void updateText() {
if (!m_task)
setText(
m_backup->description(
Preferences::instance().general.showFullPath()));
}
private: private:
void onSizeHint(SizeHintEvent& ev) override { void onSizeHint(SizeHintEvent& ev) override {
ListItem::onSizeHint(ev); ListItem::onSizeHint(ev);
@ -238,6 +245,15 @@ DataRecoveryView::DataRecoveryView(crash::DataRecovery* dataRecovery)
m_listBox.Change.connect(base::Bind(&DataRecoveryView::onChangeSelection, this)); m_listBox.Change.connect(base::Bind(&DataRecoveryView::onChangeSelection, this));
m_listBox.DoubleClickItem.connect(base::Bind(&DataRecoveryView::onOpen, this)); m_listBox.DoubleClickItem.connect(base::Bind(&DataRecoveryView::onOpen, this));
m_waitToEnableRefreshTimer.Tick.connect(base::Bind(&DataRecoveryView::onCheckIfWeCanEnableRefreshButton, this)); m_waitToEnableRefreshTimer.Tick.connect(base::Bind(&DataRecoveryView::onCheckIfWeCanEnableRefreshButton, this));
m_conn = Preferences::instance()
.general.showFullPath.AfterChange.connect(
[this](const bool&){ onShowFullPathPrefChange(); });
}
DataRecoveryView::~DataRecoveryView()
{
m_conn.disconnect();
} }
void DataRecoveryView::refreshListNotification() void DataRecoveryView::refreshListNotification()
@ -487,6 +503,16 @@ void DataRecoveryView::onCheckIfWeCanEnableRefreshButton()
m_view.updateView(); m_view.updateView();
} }
void DataRecoveryView::onShowFullPathPrefChange()
{
for (auto widget : m_listBox.children()) {
if (auto item = dynamic_cast<Item*>(widget)) {
if (!item->isTaskRunning())
item->updateText();
}
}
}
bool DataRecoveryView::thereAreCrashSessions() const bool DataRecoveryView::thereAreCrashSessions() const
{ {
for (auto widget : m_listBox.children()) { for (auto widget : m_listBox.children()) {

View File

@ -28,6 +28,7 @@ namespace app {
, public WorkspaceView { , public WorkspaceView {
public: public:
DataRecoveryView(crash::DataRecovery* dataRecovery); DataRecoveryView(crash::DataRecovery* dataRecovery);
~DataRecoveryView();
// Called after the "Refresh" button is pressed (onRefresh) and // Called after the "Refresh" button is pressed (onRefresh) and
// the crash::DataRecovery::SessionsListIsReady signal is received. // the crash::DataRecovery::SessionsListIsReady signal is received.
@ -60,6 +61,7 @@ namespace app {
void onRefresh(); void onRefresh();
void onChangeSelection(); void onChangeSelection();
void onCheckIfWeCanEnableRefreshButton(); void onCheckIfWeCanEnableRefreshButton();
void onShowFullPathPrefChange();
bool thereAreCrashSessions() const; bool thereAreCrashSessions() const;
crash::DataRecovery* m_dataRecovery; crash::DataRecovery* m_dataRecovery;
@ -69,6 +71,10 @@ namespace app {
ui::Button m_deleteButton; ui::Button m_deleteButton;
ui::Button m_refreshButton; ui::Button m_refreshButton;
ui::Timer m_waitToEnableRefreshTimer; ui::Timer m_waitToEnableRefreshTimer;
// Connection to to showFullPath.AfterChange signal to update the
// items text when the setting is changed.
obs::connection m_conn;
}; };
} // namespace app } // namespace app