Skip to content

Commit

Permalink
gtkmm - update_window_save_needed...
Browse files Browse the repository at this point in the history
  • Loading branch information
giuspen committed Oct 26, 2019
1 parent fca916d commit 8e5bb06
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 27 deletions.
4 changes: 2 additions & 2 deletions future/src/ct/ct_actions_find.cc
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,12 @@ Gtk::TextIter CtActions::_get_inner_start_iter(Glib::RefPtr<Gtk::TextBuffer> tex
//"""Returns True if the given node_iter is within the Time Filter"""
bool CtActions::_is_node_within_time_filter(const CtTreeIter& node_iter)
{
std::time_t ts_cre = node_iter.get_node_creating_time();
gint64 ts_cre = node_iter.get_node_creating_time();
if (s_options.ts_cre_after.on && ts_cre < s_options.ts_cre_after.time)
return false;
if (s_options.ts_cre_before.on && ts_cre > s_options.ts_cre_before.time)
return false;
std::time_t ts_mod = node_iter.get_node_modification_time();
gint64 ts_mod = node_iter.get_node_modification_time();
if (s_options.ts_mod_after.on && ts_mod < s_options.ts_mod_after.time)
return false;
if (s_options.ts_mod_before.on && ts_mod > s_options.ts_mod_before.time)
Expand Down
3 changes: 1 addition & 2 deletions future/src/ct/ct_clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,9 @@ void CtClipboard::_on_clip_data_get(Gtk::SelectionData& selection_data, guint /
if (target == TARGETS_HTML[0])
{
glong utf16text_len = 0;
gunichar2* utf16text = g_utf8_to_utf16(clip_data->html_text.c_str(), (glong)clip_data->html_text.bytes(), nullptr, &utf16text_len, nullptr);
g_autofree gunichar2* utf16text = g_utf8_to_utf16(clip_data->html_text.c_str(), (glong)clip_data->html_text.bytes(), nullptr, &utf16text_len, nullptr);
if (utf16text && utf16text_len > 0)
selection_data.set(target, 8, (guint8*)utf16text, (int)utf16text_len);
g_free(utf16text);
}
else
{
Expand Down
5 changes: 2 additions & 3 deletions future/src/ct/ct_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ CtImagePng::CtImagePng(Glib::RefPtr<Gdk::Pixbuf> pixBuf,

const std::string CtImagePng::get_raw_blob()
{
gchar* pBuffer{nullptr};
gsize buffer_size;
g_autofree gchar* pBuffer{NULL};
gsize buffer_size;
_rPixbuf->save_to_buffer(pBuffer, buffer_size, "png");
const std::string rawBlob = std::string(pBuffer, buffer_size);
g_free(pBuffer);
return rawBlob;
}

Expand Down
24 changes: 20 additions & 4 deletions future/src/ct/ct_main_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ bool CtMainWin::readNodesFromGioFile(const Glib::RefPtr<Gio::File>& r_file, cons
const gchar* pFilepath{nullptr};
if (CtDocEncrypt::True == docEncrypt)
{
gchar* title = g_strdup_printf(_("Enter Password for %s"), Glib::path_get_basename(filepath).c_str());
g_autofree gchar* title = g_strdup_printf(_("Enter Password for %s"), Glib::path_get_basename(filepath).c_str());
while (true)
{
CtDialogTextEntry dialogTextEntry(title, true/*forPassword*/, this);
Expand All @@ -308,7 +308,6 @@ bool CtMainWin::readNodesFromGioFile(const Glib::RefPtr<Gio::File>& r_file, cons
break;
}
}
g_free(title);
}
else if (CtDocEncrypt::False == docEncrypt)
{
Expand Down Expand Up @@ -365,14 +364,31 @@ void CtMainWin::update_window_save_needed(const CtSaveNeededUpdType update_type,
CtTreeIter treeIter = (nullptr != give_tree_iter ? *give_tree_iter : curr_tree_iter());
if (treeIter.get_node_is_rich_text())
{
treeIter.get_node_text_buffer()->set_modified(true);
treeIter.get_node_text_buffer()->set_modified(true); // support possible change inside anchored widget which doesn't toggle modified flag
}
if (false == _fileSaveNeeded)
{
_title_update(true/*save_needed*/);
_fileSaveNeeded = true;
}

switch (update_type)
{
case CtSaveNeededUpdType::None:
break;
case CtSaveNeededUpdType::nbuf:
{
treeIter.pending_edit_db_node_buff();
g_autoptr(GDateTime) pGDateTime = g_date_time_new_now_local();
const gint64 curr_time = g_date_time_to_unix(pGDateTime);
treeIter.set_node_modification_time(curr_time);
#if 0
if (not node_id in self.latest_statusbar_update_time.keys())\
or (curr_time - self.latest_statusbar_update_time[node_id] > 60):
self.latest_statusbar_update_time[node_id] = curr_time
self.update_selected_node_statusbar_info()
#endif // 0
} break;
}
}

void CtMainWin::_on_treeview_cursor_changed()
Expand Down
9 changes: 3 additions & 6 deletions future/src/ct/ct_misc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,12 @@ std::string CtFontUtil::getFontSizeStr(const std::string& fontStr)

std::string CtFontUtil::getFontCss(const std::string& fontStr)
{
gchar* pFontCss = g_strdup_printf(
g_autofree gchar* pFontCss = g_strdup_printf(
"textview text {"
" font-family: %s;"
" font-size: %spx;"
"}", getFontFamily(fontStr).c_str(), getFontSizeStr(fontStr).c_str());
std::string fontCss(pFontCss);
g_free(pFontCss);
return fontCss;
}

Expand Down Expand Up @@ -943,17 +942,15 @@ bool CtFileSystem::isfile(const Glib::ustring& path)

Glib::ustring CtFileSystem::basename(const Glib::ustring& path)
{
const gchar* allocated_name = g_path_get_basename(path.c_str());
g_autofree const gchar* allocated_name = g_path_get_basename(path.c_str());
Glib::ustring name = allocated_name;
g_free((gpointer)allocated_name);
return name;
}

Glib::ustring CtFileSystem::dirname(const Glib::ustring& path)
{
const gchar* allocated_dir = g_path_get_dirname(path.c_str());
g_autofree const gchar* allocated_dir = g_path_get_dirname(path.c_str());
Glib::ustring dir = allocated_dir;
g_free((gpointer)allocated_dir);
return dir;
}

Expand Down
10 changes: 4 additions & 6 deletions future/src/ct/ct_p7za_iface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ extern int p7za_exec(int numArgs, char *args[]);

int CtP7zaIface::p7za_extract(const gchar* input_path, const gchar* out_dir, const gchar* passwd)
{
gchar * p_args = g_strdup_printf("7za e -p%s -w%s -bd -y -o%s %s", passwd, g_get_tmp_dir(), out_dir, input_path);
gchar **pp_args = g_strsplit(p_args, " ", 0);
g_free(p_args);
g_autofree gchar* p_args = g_strdup_printf("7za e -p%s -w%s -bd -y -o%s %s", passwd, g_get_tmp_dir(), out_dir, input_path);
gchar** pp_args = g_strsplit(p_args, " ", 0);
int ret_val = p7za_exec(8, pp_args);
g_strfreev(pp_args);
return ret_val;
}

int CtP7zaIface::p7za_archive(const gchar* input_path, const gchar* output_path, const gchar* passwd)
{
gchar * p_args = g_strdup_printf("7za a -p%s -w%s -mx1 -bd -y %s %s", passwd, g_get_tmp_dir(), output_path, input_path);
gchar **pp_args = g_strsplit(p_args, " ", 0);
g_free(p_args);
g_autofree gchar* p_args = g_strdup_printf("7za a -p%s -w%s -mx1 -bd -y %s %s", passwd, g_get_tmp_dir(), output_path, input_path);
gchar** pp_args = g_strsplit(p_args, " ", 0);
int ret_val = p7za_exec(9, pp_args);
g_strfreev(pp_args);
return ret_val;
Expand Down
9 changes: 7 additions & 2 deletions future/src/ct/ct_treestore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,21 @@ bool CtTreeIter::get_node_is_rich_text() const
return get_node_syntax_highlighting() == CtConst::RICH_TEXT_ID;
}

std::time_t CtTreeIter::get_node_creating_time() const
gint64 CtTreeIter::get_node_creating_time() const
{
return (*this) ? (*this)->get_value(_pColumns->colTsCreation) : 0;
}

std::time_t CtTreeIter::get_node_modification_time() const
gint64 CtTreeIter::get_node_modification_time() const
{
return (*this) ? (*this)->get_value(_pColumns->colTsLastSave) : 0;
}

void CtTreeIter::set_node_modification_time(const gint64 modification_time)
{
if (*this) (*this)->set_value(_pColumns->colTsLastSave, modification_time);
}

void CtTreeIter::set_node_aux_icon(Glib::RefPtr<Gdk::Pixbuf> rPixbuf)
{
(*this)->set_value(_pColumns->rColPixbufAux, rPixbuf);
Expand Down
6 changes: 4 additions & 2 deletions future/src/ct/ct_treestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class CtTreeIter : public Gtk::TreeIter
std::string get_node_foreground() const;
std::string get_node_syntax_highlighting() const;
bool get_node_is_rich_text() const;
std::time_t get_node_creating_time() const;
std::time_t get_node_modification_time() const;
gint64 get_node_creating_time() const;
gint64 get_node_modification_time() const;

void set_node_modification_time(const gint64 modification_time);
void set_node_aux_icon(Glib::RefPtr<Gdk::Pixbuf> rPixbuf);

std::list<CtAnchoredWidget*> get_all_embedded_widgets();
Expand Down

0 comments on commit 8e5bb06

Please sign in to comment.