libsaria: Remove sid_t type

I was using the sid_t to lookups for tracks and library paths.  I think
I can simplify things by storing pointers in the UI rather than using
id numbers.  This will give me direct access to whatever it is I want to
manipulate.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-18 09:22:24 -04:00
parent 230a31a5a7
commit d77b06f267
7 changed files with 16 additions and 32 deletions

View File

@ -1,13 +1,10 @@
#ifndef LIBSARIA_FS_H
#define LIBSARIA_FS_H
#include <sys/types.h>
#include <list>
#include <string>
using namespace std;
typedef ino_t sid_t;
enum DataState {
DIRTY,
CLEAN,
@ -15,7 +12,6 @@ enum DataState {
namespace libsaria
{
sid_t lookup_fileid(string &);
void list_dir(string &, list<string> &);
namespace app

View File

@ -14,7 +14,6 @@ namespace libsaria
struct Path {
bool visible;
sid_t lib_id;
string path;
};
@ -23,7 +22,7 @@ namespace libsaria
Driver();
~Driver();
virtual void path_added(Path &) = 0;
virtual void path_added(Path *) = 0;
};
void add_path(string);

View File

@ -42,15 +42,6 @@ static void handle_entry(string &dir, list<string> &file_list, struct dirent *di
namespace libsaria
{
sid_t lookup_fileid(string &filepath)
{
struct stat stat;
int err = lstat(filepath.c_str(), &stat);
if (err != 0)
return err;
return stat.st_ino;
}
void list_dir(string &dir, list<string> &file_list)
{
DIR *dp;

View File

@ -44,19 +44,15 @@ namespace libsaria
list<libsaria::library::Driver *>::iterator it;
path.visible = true;
path.lib_id = lookup_fileid(dir);
path.path = dir;
if (path.lib_id < 0)
return;
path_list.push_back(path);
/* Notify library drivers that a new path has been added */
for (it = driver_list.begin(); it != driver_list.end(); it++)
(*it)->path_added(path_list.back());
(*it)->path_added(&path_list.back());
update_path(path_list.back());
update_path(&path_list.back());
}
library::Driver::Driver()

View File

@ -3,7 +3,7 @@
#include <libsaria/library.h>
void update_path(struct libsaria::library::Path &);
void update_path(struct libsaria::library::Path *);
/*#include <string>
using namespace std;
*/

View File

@ -79,9 +79,9 @@ void ReaddirTask::run_task()
}
}
void update_path(struct libsaria::library::Path &path)
void update_path(struct libsaria::library::Path *path)
{
println("Updating path: " + path.path);
ReaddirTask *task = new ReaddirTask(&path);
println("Updating path: " + path->path);
ReaddirTask *task = new ReaddirTask(path);
task->queue();
}

View File

@ -20,27 +20,27 @@ struct library_info {
class LibraryDriver : public libsaria::library::Driver {
public:
void path_added(libsaria::library::Path &);
void path_added(libsaria::library::Path *);
};
static LibraryDriver driver;
static GtkListStore *path_list;
static struct library_info columns[] = {
library_info("Id", G_TYPE_LONG, false),
library_info("Filepath", G_TYPE_STRING, true),
library_info("Pointer", G_TYPE_POINTER, false),
library_info("Filepath", G_TYPE_STRING, true),
};
static unsigned int NUM_COLUMNS = sizeof(columns) / sizeof(library_info);
void LibraryDriver::path_added(libsaria::library::Path &path)
void LibraryDriver::path_added(libsaria::library::Path *path)
{
GtkTreeIter iter;
println("Path added: " + path.path);
println("Path added: " + path->path);
gtk_list_store_append(path_list, &iter);
gtk_list_store_set(path_list, &iter,
0, path.lib_id,
1, path.path.c_str(),
0, path,
1, path->path.c_str(),
-1);
}
@ -85,6 +85,8 @@ static void setup_liststore(GtkWidget *treeview)
gtk_cell_renderer_text_set_fixed_height_from_font(GTK_CELL_RENDERER_TEXT(textcell), 1);
for (unsigned int i = 0; i < NUM_COLUMNS; i++) {
if (columns[i].type == G_TYPE_POINTER)
continue;
col = gtk_tree_view_column_new_with_attributes(columns[i].name,
textcell,
"text", i,