KSplash engine Moodin - splash screen engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

magiclabel.cpp 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /***************************************************************************
  2. * Copyright (C) by *
  3. * - 2005: Christian Leh <moodwrod@web.de> *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. ***************************************************************************/
  11. #include <tqstringlist.h>
  12. #include <tqregexp.h>
  13. #include <tdelocale.h>
  14. #include <kuser.h>
  15. #include <tdemessagebox.h>
  16. #include "magiclabel.h"
  17. // This class is still very simple (as most of the classes)
  18. // They get all improved later when "OpenGL Effect Widget" structure is completed
  19. MagicLabel::MagicLabel(TQString s, bool translate)
  20. {
  21. prefix = "ML:";
  22. preUSER = "USER:";
  23. preCMD = "CMD:";
  24. mValue = s;
  25. transform();
  26. if (translate)
  27. mValue = i18n(mValue.utf8());
  28. }
  29. void MagicLabel::transform()
  30. {
  31. if (mValue.contains(prefix + preUSER))
  32. getUserInfo();
  33. else if (mValue.startsWith(prefix + preCMD))
  34. getCommandOutput();
  35. }
  36. void MagicLabel::getUserInfo()
  37. {
  38. static KUser user;
  39. if (mValue.contains(prefix + preUSER + "loginname"))
  40. mValue = mValue.replace(prefix + preUSER + "loginname", user.loginName());
  41. else if (mValue.contains(prefix + preUSER + "fullname"))
  42. mValue = mValue.replace(prefix + preUSER + "fullname", user.fullName());
  43. else if (mValue.contains(prefix + preUSER + "homedir"))
  44. mValue = mValue.replace(prefix + preUSER + "homedir", user.homeDir());
  45. }
  46. void MagicLabel::getCommandOutput()
  47. {
  48. TQString cmd = TQStringList::split(prefix + preCMD, mValue)[0];
  49. TQStringList parts = TQStringList::split(" ", cmd);
  50. KShellProcess *proc = new KShellProcess;
  51. for (int i = 0; i < parts.count(); i++)
  52. *proc << parts[i];
  53. connect(proc, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(processExited(TDEProcess*)));
  54. connect(proc, TQT_SIGNAL(receivedStdout(TDEProcess*, char*, int)), this, TQT_SLOT(receivedStdout(TDEProcess*, char*, int)));
  55. mValue = "";
  56. if (!proc->start(TDEProcess::Block, TDEProcess::Stdout))
  57. KMessageBox::information(0, TQString("Could not start process: %1").arg(cmd));
  58. }
  59. void MagicLabel::receivedStdout(TDEProcess *proc, char *buffer, int buflen)
  60. {
  61. TQString buf = TQString::fromLatin1(buffer, buflen);
  62. mValue += buf.replace("\n", "");
  63. }
  64. void MagicLabel::processExited(TDEProcess* proc)
  65. {
  66. delete proc;
  67. }
  68. #include "magiclabel.moc"