summaryrefslogtreecommitdiffstats
path: root/knetworkconf/knetworkconf/kprofileslistviewtooltip.h
blob: 15dfde86bb8f8c1b02c77d8544643a9474508545 (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 <tqtooltip.h>
#include <tqlistview.h>
#include <tqheader.h>
#include <tqptrlist.h>

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

class KProfilesListViewToolTip : public TQToolTip
{
public:
  KProfilesListViewToolTip(TQListView* tqparent);
  void setProfiles(TQPtrList<KNetworkInfo> profiles_);
  ~KProfilesListViewToolTip();

protected:
    void maybeTip( const TQPoint& p );
    KNetworkInfo *getProfile(TQPtrList<KNetworkInfo> profilesList, TQString selectedProfile);
private:
    TQListView* listView;
  //KNetworkConf* conf;
  TQPtrList<KNetworkInfo> profiles;
    
};

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

inline KProfilesListViewToolTip::KProfilesListViewToolTip( TQListView* tqparent ):TQToolTip( tqparent->viewport() ), listView( tqparent ) {}
 
inline void KProfilesListViewToolTip::maybeTip( const TQPoint& p ) 
{
 
  if ( !listView )
    return;
 
  const TQListViewItem* item = listView->itemAt( p );
 
  if ( !item )
    return;
 
  const TQRect tqitemRect = listView->tqitemRect( item );
 
  if ( !tqitemRect.isValid() )
    return;
  
  const int col = listView->header()->sectionAt( p.x() );
 
  if ( col == -1 )
    return;
 
  const TQRect headerRect = listView->header()->sectionRect( col );
 
  if ( !headerRect.isValid() )
    return;
 
  const TQRect cellRect( headerRect.left(), tqitemRect.top(),headerRect.width() + 60, tqitemRect.height() );
 
  TQString tipStr;
 
  if( col == 0 )
  {
    tipStr = TQString(i18n("<b>Network Configuration of this Profile:</b>" ));
    KNetworkInfo *profile = getProfile(profiles,item->text(0)); 
    if (profile != NULL)
    {
      TQPtrList<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").tqarg(device->getDeviceName().latin1()));
          tipStr.append(i18n("<br><b>Type:</b> %1").tqarg(device->getType()));
          TQString bootProto;
          if (device->getBootProto() == "none")
            bootProto = "Manual";
          else
            bootProto = device->getBootProto();
          tipStr.append(i18n("<br><b>Boot Protocol:</b> %1").tqarg(bootProto));
          if (bootProto != "dhcp")
          {
            tipStr.append(i18n("<br><b>IP Address:</b>   %1").tqarg(device->getIpAddress()));
            tipStr.append(i18n("<br><b>Broadcast Address:</b> %1").tqarg(device->getBroadcast()));
          }  
          tipStr.append(i18n("<br><b>On Boot:</b> %1").tqarg(device->getOnBoot()));    
        }
      }
      KRoutingInfo *route = profile->getRoutingInfo();
      tipStr.append(i18n("</p><p><b>Default Gateway:</b>   %1").tqarg(route->getGateway()));
      KDNSInfo *dns = profile->getDNSInfo();
      tipStr.append(i18n("<br><b>Domain Name:</b> %1").tqarg(dns->getDomainName()));
      tipStr.append(i18n("<br><b>Machine Name:</b> %1").tqarg(dns->getMachineName()));
      TQStringList nameServers = dns->getNameServers();
      for ( TQStringList::Iterator it = nameServers.begin(); it != nameServers.end(); ++it)
      {
        tipStr.append(i18n("<br><b>DNS Name Server:</b> %1").tqarg((*it)));
      }
    }  
  }
  tip( cellRect, tipStr );
}

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

#endif