unsigned long long TDEStorageDevice::deviceSize() { TQString bsnodename = systemPath(); bsnodename.append("/queue/physical_block_size"); TQFile bsfile( bsnodename ); TQString blocksize; if ( bsfile.open( IO_ReadOnly ) ) { TQTextStream stream( &bsfile ); blocksize = stream.readLine(); bsfile.close(); } else { // Drat, I can't get a guaranteed block size. Assume a block size of 512, as everything I have read indicates that /sys/block/<dev>/size is given in terms of a 512 byte block... blocksize = "512"; } TQString dsnodename = systemPath(); dsnodename.append("/size"); TQFile dsfile( dsnodename ); TQString devicesize; if ( dsfile.open( IO_ReadOnly ) ) { TQTextStream stream( &dsfile ); devicesize = stream.readLine(); dsfile.close(); } return ((unsigned long long)blocksize.toULong()*(unsigned long long)devicesize.toULong()); }
int main( int argc, char *argv[] ) { TDEAboutData aboutData( "ksystraycmd", I18N_NOOP( "KSysTrayCmd" ), "KSysTrayCmd 0.1", I18N_NOOP( "Allows any application to be kept in the system tray" ), TDEAboutData::License_GPL, "(C) 2001-2002 Richard Moore ([email protected])" ); aboutData.addAuthor( "Richard Moore", 0, "*****@*****.**" ); TDECmdLineArgs::init( argc, argv, &aboutData ); TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options. TDEApplication app; // // Setup the tray icon from the arguments. // TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); KSysTrayCmd cmd; // Read the window id TQString wid = args->getOption( "wid" ); if ( !wid.isEmpty() ) { int base = 10; if ( wid.startsWith( "0x" ) ) { base = 16; wid = wid.right( wid.length() - 2 ); } bool ok=true; ulong w = wid.toULong( &ok, base ); if ( ok ) cmd.setTargetWindow( w ); else { kdWarning() << "KSysTrayCmd: Got bad win id" << endl; } } // Read window title regexp TQString title = args->getOption( "window" ); if ( !title.isEmpty() ) cmd.setPattern( title ); if ( !title && !wid && (args->count() == 0) ) TDECmdLineArgs::usage(i18n("No command or window specified")); // Read the command TQString command; for ( int i = 0; i < args->count(); i++ ) command += TDEProcess::quote(TQString::fromLocal8Bit( args->arg(i) )) + " "; if ( !command.isEmpty() ) cmd.setCommand( command ); // Tooltip TQString tip = args->getOption( "tooltip" ); if ( !tip.isEmpty() ) cmd.setDefaultTip( tip ); // Keep running flag if ( args->isSet( "keeprunning" ) ) cmd.setNoQuit( true ); if ( args->isSet( "quitonhide" ) ) { cmd.setNoQuit( true ); cmd.setQuitOnHide( true ); } // Start hidden if ( args->isSet( "hidden" ) ) cmd.hideWindow(); // On top if ( args->isSet( "ontop" ) ) cmd.setOnTop(true); // Use ksystraycmd icon if ( args->isSet( "ownicon" ) ) cmd.setOwnIcon(true); // Lazy invocation flag if ( args->isSet( "startonshow" ) ) { cmd.setStartOnShow( true ); cmd.show(); } else { if ( !cmd.start() ) return 1; } fcntl(ConnectionNumber(tqt_xdisplay()), F_SETFD, 1); args->clear(); return app.exec(); }
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 }