/* Copyright 2003 Rikard Björklind, Mikael Gransell This file is part of dc-qt. dc-qt 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. dc-qt 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 dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "dc_file.h" #include dc_file::dc_file (dc_dir *p, const QString &n, const QString &s, bool d) : name(n), size(s), dir(d) { parent = p; if (parent != 0) { full_name = parent->get_full_name() + n; root_name = parent->get_root_name(); if (d) full_name += DIR_SEP; } else { full_name = ""; root_name = n; } } bool dc_dir::add_file (dc_file *f) { if (get_file (f->get_name()) != 0) return false; files.push_back (f); return true; } bool dc_dir::add_dir ( dc_dir *d) { if (get_file(d->get_name()) != 0) return false; files.push_back(d); return true; } void dc_dir::rm_file(const QString &f) { dc_file *p = get_file(f); if (p == 0) return; files.erase(get_file_itr(f)); delete p; } dc_file* dc_dir::get_file(const QString &f) { // the stl find returns end() on failure // and this was causing problems if the list // had 0 or 1 items in it if (files.size() == 0) return 0; if (files.size() == 1) { if (files.front() == f) return files.front(); else return 0; } deque::iterator i = get_file_itr(f); if ( i == files.end() && files.back() != f) return 0; else return *i; } deque::iterator dc_dir::get_file_itr(const QString &f) { return ::find(files.begin(), files.end(), f); } bool operator==(dc_file* d, const dc_file &f) { return d->operator==(f); } bool operator==(dc_file* d, const QString &f) { return d->operator==(f); } bool operator!=(dc_file* d, const dc_file &f) { return d->operator!=(f); } bool operator!=(dc_file* d, const QString &f) { return d->operator!=(f); }