File indexing completed on 2023-10-01 08:44:28
0001 /*************************************************************************** 0002 smb4knetworkbrowseritem - Smb4K's network browser list item. 0003 ------------------- 0004 begin : Mo Jan 8 2007 0005 copyright : (C) 2007-2019 by Alexander Reinholdt 0006 email : alexander.reinholdt@kdemail.net 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * This program is free software; you can redistribute it and/or modify * 0011 * it under the terms of the GNU General Public License as published by * 0012 * the Free Software Foundation; either version 2 of the License, or * 0013 * (at your option) any later version. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, but * 0016 * WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0018 * General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program; if not, write to the * 0022 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* 0023 * MA 02110-1335, USA * 0024 ***************************************************************************/ 0025 0026 #ifdef HAVE_CONFIG_H 0027 #include <config.h> 0028 #endif 0029 0030 // application specific includes 0031 #include "smb4knetworkbrowseritem.h" 0032 #include "core/smb4kglobal.h" 0033 #include "core/smb4kworkgroup.h" 0034 #include "core/smb4khost.h" 0035 #include "core/smb4kshare.h" 0036 0037 // Qt includes 0038 #include <QDebug> 0039 #include <QBrush> 0040 #include <QApplication> 0041 0042 using namespace Smb4KGlobal; 0043 0044 0045 Smb4KNetworkBrowserItem::Smb4KNetworkBrowserItem(QTreeWidget *parent, const NetworkItemPtr &item) 0046 : QTreeWidgetItem(parent, item->type()), m_item(item) 0047 { 0048 m_tooltip = new Smb4KToolTip(); 0049 m_tooltip->setup(Smb4KToolTip::NetworkBrowser, m_item); 0050 0051 switch (m_item->type()) 0052 { 0053 case Workgroup: 0054 { 0055 WorkgroupPtr workgroup = m_item.staticCast<Smb4KWorkgroup>(); 0056 setText(Network, workgroup->workgroupName()); 0057 setIcon(Network, workgroup->icon()); 0058 break; 0059 } 0060 case Host: 0061 { 0062 HostPtr host = m_item.staticCast<Smb4KHost>(); 0063 setText(Network, host->hostName()); 0064 setText(IP, host->ipAddress()); 0065 setText(Comment, host->comment()); 0066 0067 if (host->isMasterBrowser()) 0068 { 0069 for (int i = 0; i < columnCount(); ++i) 0070 { 0071 QBrush brush(Qt::darkBlue); 0072 setForeground(i, brush); 0073 } 0074 } 0075 0076 setIcon(Network, host->icon()); 0077 break; 0078 } 0079 case Share: 0080 { 0081 SharePtr share = m_item.staticCast<Smb4KShare>(); 0082 setText(Network, share->shareName()); 0083 setText(Type, share->shareTypeString()); 0084 setText(Comment, share->comment()); 0085 0086 if (!share->isPrinter() && share->isMounted()) 0087 { 0088 for (int i = 0; i < columnCount(); ++i) 0089 { 0090 QFont f = font(i); 0091 f.setItalic(true); 0092 setFont(i, f); 0093 } 0094 } 0095 0096 setIcon(Network, share->icon()); 0097 break; 0098 } 0099 default: 0100 { 0101 break; 0102 } 0103 } 0104 } 0105 0106 0107 Smb4KNetworkBrowserItem::Smb4KNetworkBrowserItem(QTreeWidgetItem *parent, const NetworkItemPtr &item) 0108 : QTreeWidgetItem(parent, item->type()), m_item(item) 0109 { 0110 m_tooltip = new Smb4KToolTip(); 0111 m_tooltip->setup(Smb4KToolTip::NetworkBrowser, m_item); 0112 0113 switch (m_item->type()) 0114 { 0115 case Workgroup: 0116 { 0117 WorkgroupPtr workgroup = m_item.staticCast<Smb4KWorkgroup>(); 0118 setText(Network, workgroup->workgroupName()); 0119 setIcon(Network, workgroup->icon()); 0120 break; 0121 } 0122 case Host: 0123 { 0124 HostPtr host = m_item.staticCast<Smb4KHost>(); 0125 setText(Network, host->hostName()); 0126 setText(IP, host->ipAddress()); 0127 setText(Comment, host->comment()); 0128 0129 if (host->isMasterBrowser()) 0130 { 0131 for (int i = 0; i < columnCount(); ++i) 0132 { 0133 QBrush brush(Qt::darkBlue); 0134 setForeground(i, brush); 0135 } 0136 } 0137 0138 setIcon(Network, host->icon()); 0139 break; 0140 } 0141 case Share: 0142 { 0143 SharePtr share = m_item.staticCast<Smb4KShare>(); 0144 setText(Network, share->shareName()); 0145 setText(Type, share->shareTypeString()); 0146 setText(Comment, share->comment()); 0147 0148 if (!share->isPrinter() && share->isMounted()) 0149 { 0150 for (int i = 0; i < columnCount(); ++i) 0151 { 0152 QFont f = font(i); 0153 f.setItalic(true); 0154 setFont(i, f); 0155 } 0156 } 0157 0158 setIcon(Network, share->icon()); 0159 break; 0160 } 0161 default: 0162 { 0163 break; 0164 } 0165 } 0166 } 0167 0168 0169 0170 Smb4KNetworkBrowserItem::~Smb4KNetworkBrowserItem() 0171 { 0172 delete m_tooltip; 0173 } 0174 0175 0176 WorkgroupPtr Smb4KNetworkBrowserItem::workgroupItem() 0177 { 0178 if (!m_item || (m_item && m_item->type() != Workgroup)) 0179 { 0180 return WorkgroupPtr(); 0181 } 0182 0183 return m_item.staticCast<Smb4KWorkgroup>(); 0184 } 0185 0186 0187 HostPtr Smb4KNetworkBrowserItem::hostItem() 0188 { 0189 if (!m_item || (m_item && m_item->type() != Host)) 0190 { 0191 return HostPtr(); 0192 } 0193 0194 return m_item.staticCast<Smb4KHost>(); 0195 } 0196 0197 0198 SharePtr Smb4KNetworkBrowserItem::shareItem() 0199 { 0200 if (!m_item || (m_item && m_item->type() != Share)) 0201 { 0202 return SharePtr(); 0203 } 0204 0205 return m_item.staticCast<Smb4KShare>(); 0206 } 0207 0208 0209 const NetworkItemPtr &Smb4KNetworkBrowserItem::networkItem() 0210 { 0211 return m_item; 0212 } 0213 0214 0215 void Smb4KNetworkBrowserItem::update() 0216 { 0217 switch (m_item->type()) 0218 { 0219 case Host: 0220 { 0221 HostPtr host = m_item.staticCast<Smb4KHost>(); 0222 0223 // Adjust the item's color. 0224 if (host->isMasterBrowser()) 0225 { 0226 for (int i = 0; i < columnCount(); ++i) 0227 { 0228 QBrush brush(Qt::darkBlue); 0229 setForeground(i, brush); 0230 } 0231 } 0232 else 0233 { 0234 for (int i = 0; i < columnCount(); ++i) 0235 { 0236 QBrush brush = QApplication::palette().text(); 0237 setForeground(i, brush); 0238 } 0239 } 0240 0241 // Set the IP address 0242 setText(IP, host->ipAddress()); 0243 0244 // Set the comment 0245 setText(Comment, host->comment()); 0246 break; 0247 } 0248 case Share: 0249 { 0250 SharePtr share = m_item.staticCast<Smb4KShare>(); 0251 0252 // Set the comment 0253 setText(Comment, share->comment()); 0254 0255 // Set the icon 0256 setIcon(Network, share->icon()); 0257 0258 // Set the font 0259 for (int i = 0; i < columnCount(); ++i) 0260 { 0261 QFont f = font(i); 0262 f.setItalic(share->isMounted()); 0263 setFont(i, f); 0264 } 0265 0266 break; 0267 } 0268 default: 0269 { 0270 break; 0271 } 0272 } 0273 0274 m_tooltip->update(Smb4KToolTip::NetworkBrowser, m_item); 0275 } 0276 0277 0278 Smb4KToolTip* Smb4KNetworkBrowserItem::tooltip() 0279 { 0280 return m_tooltip; 0281 } 0282