Commit bee8085f authored by Jamie McCracken's avatar Jamie McCracken

added new dbus methods for File.Exists and File.GetServiceType

parent 8861e0c8
2006-07-03 Marcus Fritzsch <fritschy@googlemail.com>
* Patch to make sure query is not null in tracker_exec_sql
2006-07-03 Jamie McCracken <jamiemcc@gnome.org>
* Added new Dbus methods for File.Exists and File.GetServiceType
2006-07-02 Jamie McCracken <jamiemcc@gnome.org>
* Added new command line tool tracker-files
......
......@@ -117,7 +117,7 @@ lThe embedded mysql library ibmysqld.a version 5.0.19 or higher is required comp
If not present you can compile libmysqld.a by downloading source tarball for an appropriate version (5.0.19+) from the bottom of page http://dev.mysql.com/downloads/mysql/5.0.html
The following configure flags are reccommended if building mysqld.a from source: --without-server --with-embedded-server --enable-assembler --with-mysqld-ldflags --with-client-ldflags
The following configure flags are reccommended if building mysqld.a from source: --without-server --with-embedded-server --enable-assembler
Generic RPMs and tarballs are also provided for the embedded mysql library and another for the development headers at http://www.gnome.org/~jamiemcc/tracker/
......
......@@ -322,6 +322,13 @@
-->
<interface name="org.freedesktop.Tracker.Files">
<!-- Determines if the file is in tracker's database. The option auto_create if set to TRUE will register the file in the database if not already present -->
<method name="Exists">
<arg type="s" name="uri" direction="in" />
<arg type="b" name="auto_create" direction="in" />
<arg type="b" name="result" direction="out" />
</method>
<!-- creates a new entry for a file in tracker's database. This method is ueful when you want to tell Tracker about a file which it cannot see (EG a VFS file) or
the file is located outside the watch/crawl path -->
<method name="Create">
......@@ -337,6 +344,13 @@
<arg type="s" name="uri" direction="in" />
</method>
<!-- Get the Service subtype for the file -->
<method name="GetServiceType">
<arg type="s" name="uri" direction="in" />
<arg type="s" name="result" direction="out" />
</method>
<!-- Get the "File.Content" field for a file and allows you to specify the offset and amount of text to retrieve -->
<method name="GetTextContents">
<arg type="s" name="uri" direction="in" />
......
......@@ -53,3 +53,4 @@ tracker_files_LDADD = $(GLIB2_LIBS) \
install-exec-hook:
ln -fs $(DESTDIR)/$(libdir)/libmetatracker.so $(DESTDIR)/$(libdir)/libtracker.so
ln -fs $(DESTDIR)/$(libdir)/libmetatracker.so.0 $(DESTDIR)/$(libdir)/libtracker.so.0
......@@ -484,6 +484,9 @@ tracker_exec_sql (MYSQL *db, const char *query)
GTimeVal before, after;
double elapsed;
g_return_val_if_fail (query, NULL);
//tracker_log ("executing query:\n%s\n", query);
g_get_current_time (&before);
if (!lock_db ()) {
......
......@@ -27,6 +27,124 @@
#include "tracker-dbus-files.h"
void
tracker_dbus_method_files_exists (DBusRec *rec)
{
DBusMessage *reply;
DBConnection *db_con;
char *mime = NULL, *uri = NULL, *name, *path, *service;
gboolean auto_create;
gboolean file_valid = FALSE;
gboolean result = FALSE;
g_return_if_fail (rec && rec->user_data);
db_con = rec->user_data;
/*
<!-- Determines if the file is in tracker's database. The option auto_create if set to TRUE will register the file in the database if not already present -->
<method name="Exists">
<arg type="s" name="uri" direction="in" />
<arg type="b" name="auto_create" direction="in" />
<arg type="b" name="result" direction="out" />
</method>
*/
dbus_message_get_args (rec->message, NULL,
DBUS_TYPE_STRING, &uri,
DBUS_TYPE_BOOLEAN, &auto_create,
DBUS_TYPE_INVALID);
if (!uri) {
tracker_set_error (rec, "No file was specified");
return;
}
long file_id = tracker_db_get_file_id (db_con, uri);
result = (file_id > 0);
if (!result && auto_create) {
char *str_size;
char *str_mtime;
const char *str_is_dir;
if (uri[0] == '/') {
if (!tracker_file_is_valid (uri)) {
file_valid = FALSE;
} else {
file_valid = TRUE;
name = g_path_get_basename (uri);
path = g_path_get_dirname (uri);
mime = tracker_get_mime_type (uri);
service = tracker_get_service_type_for_mime (mime);
FileInfo *info = tracker_create_file_info (uri, 1, 0, 0);
info = tracker_get_file_info (info);
if (info) {
str_size = tracker_long_to_str (info->file_size);
str_mtime = tracker_long_to_str (info->mtime);
if (info->is_directory) {
str_is_dir = "1";
} else {
str_is_dir = "0";
}
info = tracker_free_file_info (info);
}
}
} else {
name = tracker_get_vfs_name (uri);
path = tracker_get_vfs_path (uri);
file_valid = TRUE;
mime = g_strdup ("unknown");
service = g_strdup ("VFS Files");
str_size = g_strdup ("0");
str_mtime = g_strdup ("0");
str_is_dir = "0";
}
if (file_valid) {
tracker_exec_proc (db_con->db, "CreateService", 8, path, name, service, str_is_dir, "0", "0", "0", str_mtime);
}
file_id = tracker_db_get_file_id (db_con, uri);
char *str_file_id = tracker_long_to_str (file_id);
if (file_id > 0) {
tracker_exec_proc (db_con->db, "SetMetadata", 5, service, str_file_id, "File.Modified", str_mtime, "1");
tracker_exec_proc (db_con->db, "SetMetadata", 5, service, str_file_id, "File.Size", str_size, "1");
tracker_exec_proc (db_con->db, "SetMetadata", 5, service, str_file_id, "File.Name", name, "1");
tracker_exec_proc (db_con->db, "SetMetadata", 5, service, str_file_id, "File.Path", path, "1");
tracker_exec_proc (db_con->db, "SetMetadata", 5, service, str_file_id, "File.Format", mime, "1");
}
g_free (mime);
g_free (service);
g_free (str_mtime);
g_free (str_size);
g_free (name);
g_free (path);
g_free (str_file_id);
}
reply = dbus_message_new_method_return (rec->message);
dbus_message_append_args (reply,
DBUS_TYPE_BOOLEAN, &result,
DBUS_TYPE_INVALID);
dbus_connection_send (rec->connection, reply, NULL);
dbus_message_unref (reply);
}
void
tracker_dbus_method_files_create (DBusRec *rec)
{
......@@ -181,6 +299,68 @@ tracker_dbus_method_files_delete (DBusRec *rec)
}
void
tracker_dbus_method_files_get_service_type (DBusRec *rec)
{
DBConnection *db_con;
DBusMessage *reply;
char *uri;
/*
<!-- Get the Service subtype for the file -->
<method name="GetServiceType">
<arg type="s" name="uri" direction="in" />
<arg type="s" name="result" direction="out" />
</method>
*/
g_return_if_fail (rec && rec->user_data);
db_con = rec->user_data;
dbus_message_get_args (rec->message, NULL,
DBUS_TYPE_STRING, &uri,
DBUS_TYPE_INVALID);
if (!uri) {
tracker_set_error (rec, "No file was specified");
return;
}
long id = tracker_db_get_file_id (db_con, uri);
if (id < 1) {
tracker_set_error (rec, "File %s was not found in Tracker's database", uri);
return;
}
char *str_id = tracker_long_to_str (id);
char *mime = tracker_get_metadata (db_con, "Files", str_id, "File.Format");
char *result = tracker_get_service_type_for_mime (mime);
g_free (mime);
g_free (str_id);
reply = dbus_message_new_method_return (rec->message);
dbus_message_append_args (reply,
DBUS_TYPE_STRING, &result,
DBUS_TYPE_INVALID);
g_free (result);
dbus_connection_send (rec->connection, reply, NULL);
dbus_message_unref (reply);
}
void
tracker_dbus_method_files_get_text_contents (DBusRec *rec)
{
......
......@@ -19,8 +19,10 @@
#include "tracker-dbus.h"
void tracker_dbus_method_files_exists (DBusRec *rec);
void tracker_dbus_method_files_create (DBusRec *rec);
void tracker_dbus_method_files_delete (DBusRec *rec);
void tracker_dbus_method_files_get_service_type (DBusRec *rec);
void tracker_dbus_method_files_get_text_contents (DBusRec *rec);
void tracker_dbus_method_files_search_text_contents (DBusRec *rec);
void tracker_dbus_method_files_get_mtime (DBusRec *rec);
......
......@@ -271,7 +271,11 @@ message_func (DBusConnection *conn,
} else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_EXISTS)) {
dbus_message_ref (message);
rec->action = DBUS_ACTION_FILES_EXISTS;
g_async_queue_push (user_request_queue, rec);
} else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_CREATE)) {
......@@ -286,6 +290,11 @@ message_func (DBusConnection *conn,
rec->action = DBUS_ACTION_FILES_DELETE;
g_async_queue_push (user_request_queue, rec);
} else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_SERVICE_TYPE)) {
dbus_message_ref (message);
rec->action = DBUS_ACTION_FILES_GET_SERVICE_TYPE;
g_async_queue_push (user_request_queue, rec);
} else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_TEXT_CONTENTS )) {
......
......@@ -67,8 +67,10 @@
#define TRACKER_METHOD_SEARCH_QUERY "Query"
/* File Interface */
#define TRACKER_METHOD_FILES_EXISTS "Exists"
#define TRACKER_METHOD_FILES_CREATE "Create"
#define TRACKER_METHOD_FILES_DELETE "Delete"
#define TRACKER_METHOD_FILES_GET_SERVICE_TYPE "GetServiceType"
#define TRACKER_METHOD_FILES_GET_TEXT_CONTENTS "GetTextContents"
#define TRACKER_METHOD_FILES_SEARCH_TEXT_CONTENTS "SearchTextContents"
#define TRACKER_METHOD_FILES_GET_BY_SERVICE_TYPE "GetByServiceType"
......@@ -123,8 +125,10 @@ typedef enum {
DBUS_ACTION_SEARCH_MATCHING_FIELDS,
DBUS_ACTION_SEARCH_QUERY,
DBUS_ACTION_FILES_EXISTS,
DBUS_ACTION_FILES_CREATE,
DBUS_ACTION_FILES_DELETE,
DBUS_ACTION_FILES_GET_SERVICE_TYPE,
DBUS_ACTION_FILES_GET_TEXT_CONTENTS,
DBUS_ACTION_FILES_SEARCH_TEXT_CONTENTS,
DBUS_ACTION_FILES_GET_BY_SERVICE_TYPE,
......
......@@ -1437,7 +1437,14 @@ process_user_request_queue_thread (GMutex *mutex)
break;
case DBUS_ACTION_FILES_EXISTS:
tracker_dbus_method_files_exists (rec);
break;
case DBUS_ACTION_FILES_CREATE:
......@@ -1453,6 +1460,12 @@ process_user_request_queue_thread (GMutex *mutex)
break;
case DBUS_ACTION_FILES_GET_SERVICE_TYPE:
tracker_dbus_method_files_get_service_type (rec);
break;
case DBUS_ACTION_FILES_GET_TEXT_CONTENTS:
tracker_dbus_method_files_get_text_contents (rec);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment