ocarina: Add an update_all() button
Click to update all library paths. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
34dd1a1088
commit
97a7edce41
|
@ -39,6 +39,7 @@ namespace libsaria
|
|||
void delete_path(Path *);
|
||||
void update_path(Path *);
|
||||
void save_path(Path *);
|
||||
void update_all();
|
||||
|
||||
void hide_path(Path *);
|
||||
void show_path(Path *);
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
/* library.cpp */
|
||||
void init_library();
|
||||
|
||||
/* ocarina.cpp */
|
||||
string lib_file(const string &);
|
||||
GObject *get_object(const string &);
|
||||
|
|
|
@ -135,13 +135,13 @@ namespace libsaria
|
|||
|
||||
void library::update_path(Path *path)
|
||||
{
|
||||
list<Path>::iterator it;
|
||||
|
||||
if (path) {
|
||||
if (path)
|
||||
do_update_path(path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void library::update_all()
|
||||
{
|
||||
list<Path>::iterator it;
|
||||
for (it = path_list.begin(); it != path_list.end(); it++)
|
||||
do_update_path(&(*it));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <libsaria/library.h>
|
||||
#include <ocarina/ocarina.h>
|
||||
|
||||
/*
|
||||
* TODO: Can I make a notification system, please? I think it'll
|
||||
* be easier than creating instances of static classes and
|
||||
* overriding virtual functions to do what I need.
|
||||
*/
|
||||
class LibraryDriver : public libsaria::library::Driver {
|
||||
public:
|
||||
void path_added(libsaria::library::Path *);
|
||||
void path_updated(libsaria::library::Path *);
|
||||
void path_removed(libsaria::library::Path *);
|
||||
};
|
||||
|
||||
static LibraryDriver driver;
|
||||
|
||||
static inline GtkListStore *get_list()
|
||||
{
|
||||
return GTK_LIST_STORE(get_object("LibraryList"));
|
||||
}
|
||||
|
||||
static bool find_path(libsaria::library::Path *path, GtkTreeIter *iter)
|
||||
{
|
||||
libsaria::library::Path *list_path;
|
||||
|
||||
/* get_iter_first() return FALSE if the liststore is empty */
|
||||
if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(get_list()), iter))
|
||||
return false;
|
||||
|
||||
do {
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(get_list()), iter, 0, &list_path, -1);
|
||||
if (list_path == path)
|
||||
return true;
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(get_list()), iter));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LibraryDriver::path_updated(libsaria::library::Path *path)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
if (!find_path(path, &iter))
|
||||
return;
|
||||
|
||||
gtk_list_store_set(get_list(), &iter,
|
||||
1, path->visible,
|
||||
2, path->path.c_str(),
|
||||
3, path->tracks.size(),
|
||||
-1);
|
||||
}
|
||||
|
||||
void LibraryDriver::path_added(libsaria::library::Path *path)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
println("Path added: " + path->path);
|
||||
gtk_list_store_append(get_list(), &iter);
|
||||
gtk_list_store_set(get_list(), &iter,
|
||||
0, path,
|
||||
1, path->visible,
|
||||
2, path->path.c_str(),
|
||||
3, path->tracks.size(),
|
||||
-1);
|
||||
}
|
||||
|
||||
void LibraryDriver::path_removed(libsaria::library::Path *path)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
if (!find_path(path, &iter))
|
||||
return;
|
||||
gtk_list_store_remove(get_list(), &iter);
|
||||
}
|
||||
|
||||
static void update_libraries(GtkWidget *b, gpointer d)
|
||||
{
|
||||
libsaria::library::update_all();
|
||||
}
|
||||
|
||||
void init_library()
|
||||
{
|
||||
connect_signal("UpdateLibraries", "clicked", G_CALLBACK(update_libraries), NULL);
|
||||
}
|
|
@ -101,6 +101,7 @@ static void init(int argc, char **argv)
|
|||
|
||||
/* Initialize window */
|
||||
init_window();
|
||||
init_library();
|
||||
init_playlist();
|
||||
init_status();
|
||||
|
||||
|
|
|
@ -464,7 +464,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="RefreshLibraries">
|
||||
<object class="GtkButton" id="UpdateLibraries">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
|
|
Loading…
Reference in New Issue