File Database::getFileByPath(const QString &path)
{
File f;
+ QString mappedPath = MyList::instance()->mapPathToSource(path);
QSqlQuery &q = prepare(
"SELECT f.fid, f.eid, f.aid, f.gid, f.entry_added, f.anidb_update, f.entry_update, f.my_update, "
" FROM file f "
" JOIN file_location fl ON (fl.fid = f.fid) "
" WHERE fl.path = :path ");
- q.bindValue(":path", path);
+ q.bindValue(":path", mappedPath);
if (!exec(q))
return File();
data.hostId = q.value(5).toInt();
data.localPath = q.value(4).toString();
- data.path = MyList::instance()->mapPath(data.hostId, data.localPath);
+ data.path = MyList::instance()->mapPathFromSource(data.localPath, data.hostId);
if (!data.path.isEmpty())
break;
emit taskCountChanged();
}
-QString MyList::mapPath(int sourceHost, const QString &path)
+QString MyList::mapPathFromSource(const QString &path, int sourceHost)
{
if (sourceHost == hostId())
return path;
return QString();
}
+QString MyList::mapPathToSource(const QString &path, int *sourceHost)
+{
+ QList<PathMapping> mappings = db->getMappingsToHost(hostId());
+
+ foreach(const PathMapping &pm, mappings)
+ {
+ QString prefix = pm.destinationPrefix;
+ if (!prefix.endsWith(QChar('/')))
+ prefix.append(QChar('/'));
+
+ if (!path.startsWith(prefix))
+ continue;
+
+ QString ret = pm.sourcePrefix;
+
+ if (!ret.endsWith(QChar('/')))
+ ret.append(QChar('/'));
+ ret.append(path.mid(prefix.length()));
+
+ if (sourceHost)
+ *sourceHost = pm.sourceHost;
+
+ return ret;
+ }
+
+ if (sourceHost)
+ *sourceHost = hostId();
+
+ return path;
+}
+
void MyList::taskFinished()
{
AbstractTask *task = qobject_cast<AbstractTask *>(sender());
AbstractTask *importMyList(const QFileInfo &file);
void executeTask(AbstractTask *task);
- QString mapPath(int sourceHost, const QString &path);
+ QString mapPathFromSource(const QString &path, int sourceHost);
+ QString mapPathToSource(const QString &path, int *sourceHost = 0);
void setupUdpClient();
void setupRequestHandler();