00001 /* 00002 Copyright (C) 2008-2010 Lukas Sommer < SommerLuk at gmail dot com > 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License as 00006 published by the Free Software Foundation; either version 2 of 00007 the License or (at your option) version 3 or any later version 00008 accepted by the membership of KDE e.V. (or its successor approved 00009 by the membership of KDE e.V.), which shall act as a proxy 00010 defined in Section 14 of version 3 of the license. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "stationlistitem.h" 00022 00023 #include <QFile> 00024 00025 stationlistItem::stationlistItem(const QString & folderName) 00026 { 00027 m_itemType = folder; 00028 m_folderName = folderName; 00029 initialize(); 00030 } 00031 00032 stationlistItem::stationlistItem(radioStation *streamObject) 00033 { 00034 m_itemType = stream; 00035 m_radiostation = streamObject; 00036 initialize(); 00037 }; 00038 00039 stationlistItem::~stationlistItem() 00040 { 00041 foreach (stationlistItem *entry, childItems) { 00042 delete entry; 00043 }; 00044 } 00045 00046 void stationlistItem::initialize() 00047 { 00048 parentItem = 0; 00049 self = this; 00050 } 00051 00052 int stationlistItem::childCount() const 00053 { 00054 return childItems.size(); 00055 } 00056 00057 stationlistItem *stationlistItem::child(int row) const 00058 { 00059 if (childItems.size() > row) { 00060 return childItems.value(row); 00061 } else { 00062 return 0; 00063 }; 00064 } 00065 00066 bool stationlistItem::appendChild(stationlistItem *child) 00067 { 00068 if (m_itemType == folder) { 00069 child->parentItem = this; 00070 childItems.append(child); 00071 return true; 00072 } else { 00073 return false; 00074 }; 00075 } 00076 00077 bool stationlistItem::insertChild(stationlistItem *child, int row) 00078 { 00079 if (m_itemType == folder) { 00080 if (row < 0) { 00081 row = 0; 00082 } else if (row > childCount()) { 00083 row = childCount(); 00084 }; 00085 child->parentItem = this; 00086 childItems.insert(row, child); 00087 return true; 00088 } else { 00089 return false; 00090 }; 00091 } 00092 00093 void stationlistItem::detach() 00094 { 00095 if (parentItem) { // this is a child item 00096 parentItem->childItems.removeAt(row()); 00097 parentItem = 0; 00098 }; 00099 } 00100 00101 int stationlistItem::row() const 00102 { 00103 if (parentItem) { // this is a child item 00104 return parentItem->childItems.indexOf(self); 00105 } else { // this is a root item 00106 return 0; 00107 }; 00108 } 00109 00110 stationlistItem *stationlistItem::parent() const 00111 { 00112 return parentItem; 00113 } 00114 00115 stationlistItem::itemType stationlistItem::type() const 00116 { 00117 return m_itemType; 00118 }; 00119 00120 radioStation *stationlistItem::streamObject() const 00121 { 00122 return m_radiostation; 00123 }; 00124 00125 QString stationlistItem::folderName() const 00126 { 00127 return m_folderName; 00128 }; 00129 00130 void stationlistItem::setFolderName(const QString & folderName) 00131 { 00132 m_folderName = folderName; 00133 }