summaryrefslogtreecommitdiffstats
path: root/knetworkconf/knetworkconf/kprofileslistviewtooltip.h
blob: c0c6bcefe77dd7dc71b26976a1f63ec7406c7a43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
                          kprofileslistviewtooltip.h  -  description
                             -------------------
    begin                : Wed Aug 24 2005
    copyright            : (C) 2005 by Juan Luis Baptiste
    email                : juan.baptiste@kdemail.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.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef KPROFILESLISTVIEWTOOLTIP_H
#define KPROFILESLISTVIEWTOOLTIP_H

#include <qtooltip.h>
#include <qlistview.h>
#include <qheader.h>
#include <qptrlist.h>

#include "knetworkinfo.h"
#include "knetworkconfigparser.h"

class KProfilesListViewToolTip : public QToolTip
{
public:
  KProfilesListViewToolTip(QListView* parent);
  void setProfiles(QPtrList<KNetworkInfo> profiles_);
  ~KProfilesListViewToolTip();

protected:
    void maybeTip( const QPoint& p );
    KNetworkInfo *getProfile(QPtrList<KNetworkInfo> profilesList, QString selectedProfile);
private:
    QListView* listView;
  //KNetworkConf* conf;
  QPtrList<KNetworkInfo> profiles;
    
};

inline void KProfilesListViewToolTip::setProfiles(QPtrList<KNetworkInfo> profiles_)
{
  profiles = profiles_;
}

inline KProfilesListViewToolTip::KProfilesListViewToolTip( QListView* parent ):QToolTip( parent->viewport() ), listView( parent ) {}
 
inline void KProfilesListViewToolTip::maybeTip( const QPoint& p ) 
{
 
  if ( !listView )
    return;
 
  const QListViewItem* item = listView->itemAt( p );
 
  if ( !item )
    return;
 
  const QRect itemRect = listView->itemRect( item );
 
  if ( !itemRect.isValid() )
    return;
  
  const int col = listView->header()->sectionAt( p.x() );
 
  if ( col == -1 )
    return;
 
  const QRect headerRect = listView->header()->sectionRect( col );
 
  if ( !headerRect.isValid() )
    return;
 
  const QRect cellRect( headerRect.left(), itemRect.top(),headerRect.width() + 60, itemRect.height() );
 
  QString tipStr;
 
  if( col == 0 )
  {
    tipStr = QString(i18n("<b>Network Configuration of this Profile:</b>" ));
    KNetworkInfo *profile = getProfile(profiles,item->text(0)); 
    if (profile != NULL)
    {
      QPtrList<KNetworkInterface> devices = profile->getDeviceList();  
      KNetworkInterface *device = NULL;
      for (device = devices.first(); device; device = devices.next())
      {
        if (device->getType() != LOOPBACK_IFACE_TYPE)
        {
          tipStr.append(i18n("<p><b>Interface:</b> %1").arg(device->getDeviceName().latin1()));
          tipStr.append(i18n("<br><b>Type:</b> %1").arg(device->getType()));
          QString bootProto;
          if (device->getBootProto() == "none")
            bootProto = "Manual";
          else
            bootProto = device->getBootProto();
          tipStr.append(i18n("<br><b>Boot Protocol:</b> %1").arg(bootProto));
          if (bootProto != "dhcp")
          {
            tipStr.append(i18n("<br><b>IP Address:</b>   %1").arg(device->getIpAddress()));
            tipStr.append(i18n("<br><b>Broadcast Address:</b> %1").arg(device->getBroadcast()));
          }  
          tipStr.append(i18n("<br><b>On Boot:</b> %1").arg(device->getOnBoot()));    
        }
      }
      KRoutingInfo *route = profile->getRoutingInfo();
      tipStr.append(i18n("</p><p><b>Default Gateway:</b>   %1").arg(route->getGateway()));
      KDNSInfo *dns = profile->getDNSInfo();
      tipStr.append(i18n("<br><b>Domain Name:</b> %1").arg(dns->getDomainName()));
      tipStr.append(i18n("<br><b>Machine Name:</b> %1").arg(dns->getMachineName()));
      QStringList nameServers = dns->getNameServers();
      for ( QStringList::Iterator it = nameServers.begin(); it != nameServers.end(); ++it)
      {
        tipStr.append(i18n("<br><b>DNS Name Server:</b> %1").arg((*it)));
      }
    }  
  }
  tip( cellRect, tipStr );
}

inline KNetworkInfo *KProfilesListViewToolTip::getProfile(QPtrList<KNetworkInfo> profilesList, QString selectedProfile)
{
  QPtrListIterator<KNetworkInfo> it(profilesList);
  KNetworkInfo *net = NULL;
    
  while ((net = it.current()) != 0)
  {
    ++it;
    if (net->getProfileName() == selectedProfile)
      break;
  }
  return net;
}

#endif