-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index e21f191..5b23330 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -74,74 +74,80 @@ IrdaApplet::~IrdaApplet() { | |||
74 | 74 | ||
75 | int IrdaApplet::checkIrdaStatus() { | 75 | int IrdaApplet::checkIrdaStatus() { |
76 | struct ifreq ifr; | 76 | struct ifreq ifr; |
77 | 77 | ||
78 | strcpy(ifr.ifr_name, "irda0"); | 78 | strcpy(ifr.ifr_name, "irda0"); |
79 | 79 | ||
80 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 80 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
81 | return -1; | 81 | return -1; |
82 | 82 | ||
83 | return (ifr.ifr_flags & IFF_UP)?1:0; | 83 | return (ifr.ifr_flags & IFF_UP)?1:0; |
84 | } | 84 | } |
85 | 85 | ||
86 | int IrdaApplet::setIrdaStatus(int c) { | 86 | int IrdaApplet::setIrdaStatus(int c) { |
87 | struct ifreq ifr; | 87 | struct ifreq ifr; |
88 | 88 | ||
89 | strcpy(ifr.ifr_name, "irda0"); | 89 | strcpy(ifr.ifr_name, "irda0"); |
90 | 90 | ||
91 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 91 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
92 | return -1; | 92 | return -1; |
93 | 93 | ||
94 | if (c) | 94 | if (c) |
95 | ifr.ifr_flags |= IFF_UP; | 95 | ifr.ifr_flags |= IFF_UP; |
96 | else | 96 | else |
97 | ifr.ifr_flags &= ~IFF_UP; | 97 | ifr.ifr_flags &= ~IFF_UP; |
98 | 98 | ||
99 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) | 99 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) |
100 | return -1; | 100 | return -1; |
101 | 101 | ||
102 | return 0; | 102 | return 0; |
103 | } | 103 | } |
104 | 104 | ||
105 | int IrdaApplet::checkIrdaDiscoveryStatus() { | 105 | int IrdaApplet::checkIrdaDiscoveryStatus() { |
106 | |||
106 | QFile discovery("/proc/sys/net/irda/discovery"); | 107 | QFile discovery("/proc/sys/net/irda/discovery"); |
107 | char status; | ||
108 | 108 | ||
109 | discovery.open( IO_ReadOnly|IO_Raw ); | 109 | QString streamIn = "0"; |
110 | discovery.readBlock (&status, 1); | 110 | |
111 | if (discovery.open(IO_ReadOnly) ) { | ||
112 | QTextStream stream ( &discovery ); | ||
113 | streamIn = stream.read(); | ||
114 | } | ||
115 | |||
111 | discovery.close(); | 116 | discovery.close(); |
112 | 117 | ||
113 | return atoi(&status); | 118 | return( streamIn.toInt() ); |
114 | } | 119 | } |
115 | 120 | ||
121 | |||
116 | int IrdaApplet::setIrdaDiscoveryStatus(int d) { | 122 | int IrdaApplet::setIrdaDiscoveryStatus(int d) { |
117 | QFile discovery("/proc/sys/net/irda/discovery"); | 123 | QFile discovery("/proc/sys/net/irda/discovery"); |
118 | 124 | ||
119 | discovery.open( IO_WriteOnly|IO_Raw ); | 125 | discovery.open( IO_WriteOnly|IO_Raw ); |
120 | 126 | ||
121 | if (d) | 127 | if (d) |
122 | discovery.putch('1'); | 128 | discovery.putch('1'); |
123 | else | 129 | else |
124 | discovery.putch('0'); | 130 | discovery.putch('0'); |
125 | 131 | ||
126 | discovery.close(); | 132 | discovery.close(); |
127 | 133 | ||
128 | return 0; | 134 | return 0; |
129 | } | 135 | } |
130 | 136 | ||
131 | 137 | ||
132 | void IrdaApplet::showDiscovered() { | 138 | void IrdaApplet::showDiscovered() { |
133 | QFile discovery("/proc/net/irda/discovery"); | 139 | QFile discovery("/proc/net/irda/discovery"); |
134 | 140 | ||
135 | if (discovery.open(IO_ReadOnly) ) { | 141 | if (discovery.open(IO_ReadOnly) ) { |
136 | QStringList list; | 142 | QStringList list; |
137 | // since it is /proc we _must_ use QTextStream | 143 | // since it is /proc we _must_ use QTextStream |
138 | QTextStream stream ( &discovery); | 144 | QTextStream stream ( &discovery); |
139 | QString streamIn; | 145 | QString streamIn; |
140 | streamIn = stream.read(); | 146 | streamIn = stream.read(); |
141 | list = QStringList::split("\n", streamIn); | 147 | list = QStringList::split("\n", streamIn); |
142 | 148 | ||
143 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 149 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
144 | if( (*line).startsWith("nickname:") ){ | 150 | if( (*line).startsWith("nickname:") ){ |
145 | discoveredDevice = (*line).mid(((*line).find(':'))+1,(*line).find(',')-(*line).find(':')-1); | 151 | discoveredDevice = (*line).mid(((*line).find(':'))+1,(*line).find(',')-(*line).find(':')-1); |
146 | qDebug(discoveredDevice); | 152 | qDebug(discoveredDevice); |
147 | } | 153 | } |