You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.2 KiB

/***************************************************************************
* Copyright (C) 2007 by Andreas Eckstein *
* andreas.eckstein@gmx.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "trackerfindclient.h"
#include <stdio.h>
TrackerFindClient::TrackerFindClient()
{
clear();
}
TrackerFindClient::~TrackerFindClient()
{
clear();
}
bool TrackerFindClient::isEmpty()
{
return true;
}
void TrackerFindClient::clear()
{
results.clear();
}
const char *TrackerFindClient::getServiceIcon(ServiceType s)
{
switch(s)
{
case SERVICE_FILES:
return "kfind";
case SERVICE_DOCUMENTS:
return "kate2";
case SERVICE_MUSIC:
return "cdaudio_unmount";
case SERVICE_IMAGES:
return "gimp";
case SERVICE_VIDEOS:
return "folder_video";
case SERVICE_TEXT_FILES:
return "kate";
case SERVICE_DEVELOPMENT_FILES:
return "tdevelop";
default:
return "kviewshell";
}
}
ServiceType TrackerFindClient::getServiceType(FindURL &url)
{
if (!url.hasRef())
{
return SERVICE_FILES;
}
else
{
TQString ref = url.ref().lower();
if (ref=="doc"||ref=="document"||ref=="documents") {
return SERVICE_DOCUMENTS;
} else if (ref=="mus"||ref=="music") {
return SERVICE_MUSIC;
} else if (ref=="img"||ref=="image"||ref=="images") {
return SERVICE_IMAGES;
} else if (ref=="vid"||ref=="video"||ref=="videos") {
return SERVICE_VIDEOS;
} else if (ref=="txt"||ref=="text"||ref=="textfiles"||ref=="text_files") {
return SERVICE_TEXT_FILES;
} else if (ref=="dev"||ref=="development"||ref=="developmentfiles"||ref=="development_files") {
return SERVICE_DEVELOPMENT_FILES;
}
else
{
return SERVICE_OTHER_FILES;
}
}
}
bool TrackerFindClient::search(FindURL url)
{
clear();
uint limit=1024;
TrackerClient *client = NULL;
GError *error = NULL;
ServiceType type;
TQCString qcsearch = url.search().utf8();
char search[qcsearch.length()*3+1];// \0 not included!
strcpy(search, (const char*)qcsearch);
char **search_results=NULL;
client = tracker_connect(FALSE);
if (!client)
{
return false;
}
type = getServiceType(url);
search_results = tracker_search_text (client, -1, type, search, 0, limit, &error);
if (error)
{
g_error_free (error);
tracker_disconnect (client);
return false;
}
if ((!search_results))
{
tracker_disconnect (client);
return true;
}
uint i=0;
while((search_results[i]!=NULL)&&(i<=limit))
{
results.append(new FindResult(TQString::fromUtf8(search_results[i])));
i++;
}
if(search_results!=NULL)
free(search_results);
tracker_disconnect (client);
return true;
}