bool GetInfo_Sound (TQListView *lbox) { lbox->setSorting(false); if (!GetDmesgInfo(lbox, "audio", NULL)) new TQListViewItem(lbox, i18n("No audio devices found.")); // append information for each audio devices found TQListViewItem *lvitem = lbox->firstChild(); for(; lvitem; lvitem = lvitem->nextSibling()) { TQString s; int pos, len; const char *start; char *dev; s = lvitem->text(0); // The autoconf message is in form 'audio0 at auvia0: ...' if (s.find("audio") == 0 && (pos = s.find(" at ")) > 0) { pos += 4; // skip " at " start = s.ascii() + pos; len = (int) strcspn(start, ":\n\t "); dev = (char *) malloc(1 + len + 1); sprintf(dev, "^%.*s", len, start); /* safe */ GetDmesgInfo(lbox, dev, NULL); free(dev); } } return true; }
bool TDERootSystemDevice::canSetHibernationMethod() { TQString hibernationnode = "/sys/power/disk"; int rval = access (hibernationnode.ascii(), W_OK); if (rval == 0) { return TRUE; } #ifdef WITH_TDEHWLIB_DAEMONS { TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); if (dbusConn.isConnected()) { // can set hibernation method? TQT_DBusMessage msg = TQT_DBusMessage::methodCall( "org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod"); TQT_DBusMessage reply = dbusConn.sendWithReply(msg); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toBool(); } } } #endif // WITH_TDEHWLIB_DAEMONS return FALSE; }
TQString ArkUtils::getTimeStamp(const TQString &_month, const TQString &_day, const TQString &_yearOrTime) { // Make the date format sortable. // Month is in _month, day is in _day. // In _yearOrTime is either a year or a time. // If it's March, we'll see the year for all dates up to October 1999. // (five months' difference - e.g., if it's Apr, then get years up to Nov) char month[4]; strncpy(month, _month.ascii(), 3); month[3] = '\0'; int nMonth = getMonth(month); int nDay = _day.toInt(); kdDebug(1601) << "Month is " << nMonth << ", Day is " << nDay << endl; time_t t = time(0); if (t == -1) exit(1); struct tm *now = localtime(&t); int thisYear = now->tm_year + 1900; int thisMonth = now->tm_mon + 1; TQString year, timestamp; if (_yearOrTime.contains(":")) // it has a timestamp so we have to figure out the year { year.sprintf("%d", ArkUtils::getYear(nMonth, thisYear, thisMonth)); timestamp = _yearOrTime; } else { year = _yearOrTime; if (year.right(1) == " ") year = year.left(4); if (year.left(1) == " ") year = year.right(4); timestamp = "??:??"; } TQString retval; retval.sprintf("%s-%.2d-%.2d %s", year.utf8().data(), nMonth, nDay, timestamp.utf8().data()); return retval; }
void KgpgApp::openDocumentFile(const KURL& url,TQString encoding) { TQString tempOpenFile; ///////////////////////////////////////////////// if( TDEIO::NetAccess::download( url, tempOpenFile,this ) ) { TQFile qfile(tempOpenFile); if (qfile.open(IO_ReadOnly)) { TQTextStream t( &qfile ); t.setCodec(TQTextCodec::codecForName (encoding.ascii())); view->editor->setText(t.read()); qfile.close(); fileSave->setEnabled(false); editRedo->setEnabled(false); editUndo->setEnabled(false); } } }
void AddIRQLine(TQListView *lBox, TQString s) { int pos, irqnum; char numstr[3]; pos = s.find(" irq "); irqnum = (pos < 0) ? 0 : atoi(&s.ascii()[pos+5]); if (irqnum) snprintf(numstr, 3, "%02d", irqnum); else { // this should never happen strcpy(numstr, "??"); } new TQListViewItem(lBox, numstr, s); }
bool TDEStorageDevice::ejectDrive() { #ifdef WITH_UDISKS2 if (!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) { if (ejectDriveUDisks2(this)) { return TRUE; } else { printf("[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii()); fflush(stdout); } } #endif // WITH_UDISKS2 #ifdef WITH_UDISKS if (!(TDEGlobal::dirs()->findExe("udisks").isEmpty())) { if (ejectDriveUDisks(this)) { return TRUE; } else { printf("[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii()); fflush(stdout); } } #endif // WITH_UDISKS if (!(TDEGlobal::dirs()->findExe("eject").isEmpty())) { TQString command = TQString("eject -v '%1' 2>&1").arg(deviceNode()); FILE *exepipe = popen(command.ascii(), "r"); if (exepipe) { TQString eject_output; TQTextStream ts(exepipe, IO_ReadOnly); eject_output = ts.read(); int retcode = pclose(exepipe); if (retcode == 0) { return TRUE; } } printf("[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii()); fflush(stdout); } return FALSE; }
ProgramSensor::ProgramSensor(const TQString &progName, int interval, TQString encoding ) : Sensor( interval ) { if( !encoding.isEmpty()) { codec = TQTextCodec::codecForName( encoding.ascii() ); if ( codec == 0) codec = TQTextCodec::codecForLocale(); } else codec = TQTextCodec::codecForLocale(); programName = progName; //update(); connect(&ksp, TQT_SIGNAL(receivedStdout(TDEProcess *, char *, int )), this,TQT_SLOT(receivedStdout(TDEProcess *, char *, int ))); connect(&ksp, TQT_SIGNAL(processExited(TDEProcess *)), this,TQT_SLOT(processExited( TDEProcess * ))); }
bool EXRCreator::create(const TQString &path, int, int, TQImage &img) { Imf::InputFile in ( path.ascii() ); const Imf::Header &h = in.header(); if ( h.hasPreviewImage() ) { kdDebug() << "EXRcreator - using preview" << endl; const Imf::PreviewImage &preview = in.header().previewImage(); TQImage qpreview(preview.width(), preview.height(), 32, 0, TQImage::BigEndian); for ( unsigned int y=0; y < preview.height(); y++ ) { for ( unsigned int x=0; x < preview.width(); x++ ) { const Imf::PreviewRgba &q = preview.pixels()[x+(y*preview.width())]; qpreview.setPixel( x, y, tqRgba(q.r, q.g, q.b, q.a) ); } } img = qpreview; return true; } else { // do it the hard way // We ignore maximum size when just extracting the thumnail // from the header, but it is very expensive to render large // EXR images just to turn it into an icon, so we go back // to honouring it in here. kdDebug() << "EXRcreator - using original image" << endl; TDEConfig * config = TDEGlobal::config(); TDEConfigGroupSaver cgs( config, "PreviewSettings" ); unsigned long long maxSize = config->readNumEntry( "MaximumSize", 1024*1024 /* 1MB */ ); unsigned long long fileSize = TQFile( path ).size(); if ( (fileSize > 0) && (fileSize < maxSize) ) { if (!img.load( path )) { return false; } if (img.depth() != 32) img = img.convertDepth( 32 ); return true; } else { return false; } } }
bool TDERootSystemDevice::canFreeze() { // Network file systems mounted on $HOME typically cause nasty suspend/resume failures // See Bug 1615 for details if (isNetworkFileSystem(TDEStorageDevice::determineFileSystemType(TDEGlobal::dirs()->localtdedir()))) { return FALSE; } TQString statenode = "/sys/power/state"; int rval = access (statenode.ascii(), W_OK); if (rval == 0) { if (powerStates().contains(TDESystemPowerState::Freeze)) { return TRUE; } else { return FALSE; } } #ifdef WITH_TDEHWLIB_DAEMONS { TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); if (dbusConn.isConnected()) { // can freeze? TQT_DBusMessage msg = TQT_DBusMessage::methodCall( "org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze"); TQT_DBusMessage reply = dbusConn.sendWithReply(msg); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toBool(); } } } #endif // WITH_TDEHWLIB_DAEMONS return FALSE; }
void EvaQunMemberPicker::updateBuddyListView() { //if(!mQun) return; lvBuddyList->clear(); TQTextCodec *codec = TQTextCodec::codecForName("GB18030"); std::list<std::string> names = EvaMain::user->getGroupNames(); std::list<std::string>::iterator groupIter; int i=0; for(groupIter = names.begin(); groupIter!= names.end(); ++groupIter){ TQString g = codec->toUnicode(groupIter->c_str()); TQCheckListItem *item = new TQCheckListItem(lvBuddyList, g, TQCheckListItem::CheckBox); item->setState(TQCheckListItem::Off); groups[i++] = item; } //QunInfo info = mQun->getDetails(); std::map<unsigned int, TQQFriend>::iterator iter; std::map<unsigned int, TQQFriend> list = (EvaMain::user->getFriendList()).getAllFriendsMap(); for(iter = list.begin(); iter != list.end(); ++iter){ int id = iter->second.getQQ(); TQString nick = EvaTextFilter::filter(codec->toUnicode(iter->second.getNick().c_str())); int groupIndex = iter->second.getGroupIndex(); TQCheckListItem *group = groups[groupIndex]; if(!group) continue; short faceID = (iter->second.getFace())/3 + 1; if(faceID<1) faceID = 1; TQCheckListItem *item = new TQCheckListItem(group, nick + "(" + TQString::number(id) + ")", TQCheckListItem::CheckBox); TQPixmap *pic = EvaMain::images->getFace(faceID, true); if(pic) { TQImage img(pic->convertToImage().smoothScale(16, 16)); item->setPixmap(0, TQPixmap(img)); }else{ fprintf(stderr, "EvaQunMemberPicker::updateBuddyListView (id:%d, faceID:%d, %s) -- NULL TQPixmap pointer, ignored!\n", id, faceID, nick.ascii()); } if(mQun && mQun->hasMember(id)) item->setState(TQCheckListItem::On); else item->setState(TQCheckListItem::Off); buddyList[id] = item; } }
bool TDERootSystemDevice::canHibernate() { // Network file systems mounted on $HOME typically cause nasty suspend/resume failures // See Bug 1615 for details if (isNetworkFileSystem(TDEStorageDevice::determineFileSystemType(TDEGlobal::dirs()->localtdedir()))) { return FALSE; } TQString statenode = "/sys/power/state"; int rval = access (statenode.ascii(), W_OK); if (rval == 0) { if (powerStates().contains(TDESystemPowerState::Hibernate)) { return TRUE; } else { return FALSE; } } #ifdef WITH_UPOWER { TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); if (dbusConn.isConnected()) { TQT_DBusProxy upowerProperties("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", dbusConn); if (upowerProperties.canSend()) { // can hibernate? TQValueList<TQT_DBusData> params; params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate"); TQT_DBusMessage reply = upowerProperties.sendWithReply("Get", params); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toVariant().value.toBool(); } } } } #endif// WITH_UPOWER #ifdef WITH_DEVKITPOWER { TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); if (dbusConn.isConnected()) { TQT_DBusProxy devkitpowerProperties("org.freedesktop.DeviceKit.Power", "/org/freedesktop/DeviceKit/Power", "org.freedesktop.DBus.Properties", dbusConn); if (devkitpowerProperties.canSend()) { // can hibernate? TQValueList<TQT_DBusData> params; params << TQT_DBusData::fromString(devkitpowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate"); TQT_DBusMessage reply = devkitpowerProperties.sendWithReply("Get", params); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toVariant().value.toBool(); } } } } #endif// WITH_DEVKITPOWER #ifdef WITH_HAL { TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); if (dbusConn.isConnected()) { TQT_DBusProxy halProperties("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device", dbusConn); if (halProperties.canSend()) { // can hibernate? TQValueList<TQT_DBusData> params; TQT_DBusMessage reply; params.clear(); params << TQT_DBusData::fromString("power_management.can_hibernate"); reply = halProperties.sendWithReply("GetPropertyBoolean", params); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toBool(); } params.clear(); params << TQT_DBusData::fromString("power_management.can_suspend_to_disk"); reply = halProperties.sendWithReply("GetPropertyBoolean", params); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toBool(); } } } } #endif // WITH_HAL #ifdef WITH_TDEHWLIB_DAEMONS { TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus); if (dbusConn.isConnected()) { // can hibernate? TQT_DBusMessage msg = TQT_DBusMessage::methodCall( "org.trinitydesktop.hardwarecontrol", "/org/trinitydesktop/hardwarecontrol", "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate"); TQT_DBusMessage reply = dbusConn.sendWithReply(msg); if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { return reply[0].toBool(); } } } #endif // WITH_TDEHWLIB_DAEMONS return FALSE; }
TQString KURIFilterData::iconName() { if( m_bChanged ) { m_customIconPixmap = TQPixmap(); switch ( m_iType ) { case KURIFilterData::LOCAL_FILE: case KURIFilterData::LOCAL_DIR: case KURIFilterData::NET_PROTOCOL: { m_strIconName = KMimeType::iconForURL( m_pURI ); break; } case KURIFilterData::EXECUTABLE: { TQString exeName = m_pURI.url(); exeName = exeName.mid( exeName.findRev( '/' ) + 1 ); // strip path if given KService::Ptr service = KService::serviceByDesktopName( exeName ); #ifndef HAVE_ELFICON // Try to find an icon with the same name as the binary (useful for non-tde apps) // FIXME: We should only do this if the binary is in the system path somewhere, // otherwise TDE could end up showing system icons for user binaries if (service && service->icon() != TQString::fromLatin1( "unknown" )) { m_strIconName = service->icon(); } else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0, true ).isNull() ) { m_strIconName = exeName; } else { // use default m_strIconName = TQString::fromLatin1("exec"); } #else // HAVE_ELFICON // Try to find an icon with the same name as the binary (useful for non-tde apps) // FIXME: We should only do this if the binary is in the system path somewhere, // otherwise TDE could end up showing system icons for user binaries if (service && service->icon() != TQString::fromLatin1( "unknown" )) { m_strIconName = service->icon(); } else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0, true ).isNull() ) { m_strIconName = exeName; } else { // use default m_strIconName = TQString::fromLatin1("exec"); } // Try to load from elf file (if supported) // Check for an embedded icon unsigned int icon_size; libr_icon *icon = NULL; libr_file *handle = NULL; libr_access_t access = LIBR_READ; char libr_can_continue = 1; if((handle = libr_open(const_cast<char*>(m_pURI.path().ascii()), access)) == NULL) { kdWarning() << "failed to open file" << m_pURI.path() << endl; libr_can_continue = 0; } if (libr_can_continue == 1) { icon_size = 32; // FIXME: Is this a reasonable size request for all possible usages of kurifilter? icon = libr_icon_geticon_bysize(handle, icon_size); if (libr_can_continue == 1) { // See if the embedded icon name matches any icon file names already on the system // If it does, use the system icon instead of the embedded one int iconresnamefound = 0; iconentry *entry = NULL; iconlist icons; if(!get_iconlist(handle, &icons)) { // Failed to obtain a list of ELF icons kdWarning() << "failed to obtain ELF icon: " << libr_errmsg() << endl; // See if there is a system icon we can use TQString sysIconName = elf_get_resource(handle, ".metadata_sysicon"); if (!sysIconName.isEmpty()) { if (TDEGlobal::iconLoader()->iconPath(sysIconName.ascii(), 0, true) != "") { m_strIconName = sysIconName; } } libr_close(handle); libr_can_continue = 0; } else { while((entry = get_nexticon(&icons, entry)) != NULL) { if(icon == NULL) { // Try loading this icon as fallback icon = libr_icon_geticon_byname(handle, entry->name); } if (TDEGlobal::iconLoader()->iconPath(entry->name, 0, true) != "") { iconresnamefound = 1; m_strIconName = entry->name; break; } } } if (libr_can_continue == 1) { if ((iconresnamefound == 0) && (icon)) { // Extract the embedded icon size_t icon_data_length; char* icondata = libr_icon_malloc(icon, &icon_data_length); m_customIconPixmap.loadFromData(static_cast<uchar*>(static_cast<void*>(icondata)), icon_data_length); // EVIL CAST if (icon_size != 0) { TQImage ip = m_customIconPixmap.convertToImage(); ip = ip.smoothScale(icon_size, icon_size); m_customIconPixmap.convertFromImage(ip); } free(icondata); libr_icon_close(icon); } libr_close(handle); } } } #endif // HAVE_ELFICON break; } case KURIFilterData::HELP: { m_strIconName = TQString::fromLatin1("khelpcenter"); break; } case KURIFilterData::SHELL: { m_strIconName = TQString::fromLatin1("konsole"); break; } case KURIFilterData::ERROR: case KURIFilterData::BLOCKED: { m_strIconName = TQString::fromLatin1("error"); break; } default: m_strIconName = TQString::null; break; } m_bChanged = false; } return m_strIconName; }
static void cleanupDCOP(int dont_kill_dcop, int wait_for_exit) { TQCString host; TQCString strDCOPServer = DCOPClient::dcopServerFile(host); if(strDCOPServer.isEmpty()) { printf("no server file\n"); return; } printf("server file %s\n",(const char *)strDCOPServer); pid_t pid = 0; TQFile f(strDCOPServer); if(f.open(IO_ReadOnly)) { TQString str; while(f.readLine(str,2048)) { pid = str.toULong(); if (pid) break; cleanupDCOPsocket(str.ascii()); } } f.close(); /* Clean up .DCOPserver file */ TQFile::remove(strDCOPServer); printf("remove server file %s\n",(const char *)strDCOPServer); if(pid) { if(!dont_kill_dcop) { #ifdef Q_OS_WIN killDCOPWin(pid); #else kill(pid, SIGTERM); #endif } else { #ifdef Q_OS_WIN killDCOPWin(pid); #endif } } #ifdef Q_OS_WIN if(wait_for_exit) { HANDLE hProcess = OpenProcess(SYNCHRONIZE,FALSE,(DWORD)pid); if(hProcess) { WaitForSingleObject(hProcess,INFINITE); CloseHandle(hProcess); } } #else while(wait_for_exit && (kill(pid, 0) == 0)) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 100000; select(0,0,0,0,&tv); } #endif }
TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) { int internal_retcode; if (!retcode) { retcode = &internal_retcode; } TQString ret = mountPath(); if (!ret.isNull()) { return ret; } // Create dummy password file KTempFile passwordFile(TQString::null, "tmp", 0600); passwordFile.setAutoDelete(true); TQFile* pwFile = passwordFile.file(); if (!pwFile) { return TQString::null; } pwFile->writeBlock(passphrase.ascii(), passphrase.length()); pwFile->flush(); TQString optionString; if (mountOptions["ro"] == "true") { optionString.append(" -r"); } if (mountOptions["atime"] != "true") { optionString.append(" -A"); } if (mountOptions["utf8"] == "true") { optionString.append(" -c utf8"); } if (mountOptions["sync"] == "true") { optionString.append(" -s"); } if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) { optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); } if (mountOptions.contains("locale")) { optionString.append(TQString(" -c %1").arg(mountOptions["locale"])); } TQString passFileName = passwordFile.name(); TQString devNode = deviceNode(); passFileName.replace("'", "'\\''"); devNode.replace("'", "'\\''"); mediaName.replace("'", "'\\''"); TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); FILE *exepipe = popen(command.local8Bit(), "r"); if (exepipe) { TQString mount_output; TQTextStream ts(exepipe, IO_ReadOnly); mount_output = ts.read(); *retcode = pclose(exepipe); if (errRet) { *errRet = mount_output; } } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; }
void KPaletteTable::readNamedColor( void ) { if( mNamedColorList->count() != 0 ) { return; // Strings already present } TDEGlobal::locale()->insertCatalogue("tdelibs_colors"); // // Code somewhat inspired by KPalette. // const char * const *path = namedColorFilePath(); for( int i=0; path[i]; ++i ) { TQFile paletteFile( path[i] ); if( !paletteFile.open( IO_ReadOnly ) ) { continue; } TQString line; TQStringList list; while( paletteFile.readLine( line, 100 ) != -1 ) { int red, green, blue; int pos = 0; if( sscanf(line.ascii(), "%d %d %d%n", &red, &green, &blue, &pos ) == 3 ) { // // Remove duplicates. Every name with a space and every name // that start with "gray". // TQString name = line.mid(pos).stripWhiteSpace(); if( name.isNull() || name.find(' ') != -1 || name.find( "gray" ) != -1 || name.find( "grey" ) != -1 ) { continue; } const TQColor color ( red, green, blue ); if ( color.isValid() ) { const TQString colorName( i18n("color", name.latin1() ) ); list.append( colorName ); d->m_namedColorMap[ colorName ] = color; } } } list.sort(); mNamedColorList->insertStringList( list ); break; } if( mNamedColorList->count() == 0 ) { // // Give the error dialog box a chance to center above the // widget (or dialog). If we had displayed it now we could get a // situation where the (modal) error dialog box pops up first // preventing the real dialog to become visible until the // error dialog box is removed (== bad UI). // TQTimer::singleShot( 10, this, TQT_SLOT(slotShowNamedColorReadError()) ); } }