Exemplo n.º 1
0
KLF_EXPORT QString klfSearchPath(const QString& programName, const QString& extra_path)
{
  static const QString PATH = getenv("PATH");
  static const QString pathsep = QString("")+KLF_PATH_SEP;

  QString path = PATH;
  if (!extra_path.isEmpty())
    path = extra_path + pathsep + path;

  const QStringList paths = str_split(path, pathsep, true);
  QString test;
  int k, j;
  for (k = 0; k < (int)paths.size(); ++k) {
    klfDbg("searching in "+paths[k]) ;
    QStringList hits = klfSearchFind(paths[k]+"/"+programName);
    klfDbg("\t...resulting in hits = "+hits.join(" ;; ")) ;
    for (j = 0; j < (int)hits.size(); ++j) {
      if ( QFileInfo(hits[j]).isExecutable() ) {
	klfDbg("\tFound definitive (executable) hit at "+hits[j]) ;
	return hits[j];
      }
    }
  }
  return QString::null;
}
Exemplo n.º 2
0
void SysTrayIconPlugin::minimize()
{
#ifdef KLF_MAC_HIDE_INSTEAD
  klfDbg("Hiding application...") ;
  _mainwin->hideApplication();
#else
  klfDbg("Hiding windows...") ;
  klfHideWindows();
  //  _mainwin->close();
#endif
}
Exemplo n.º 3
0
void KLFDebugObjectWatcher::debugObjectDestroyed(QObject *object)
{
  quintptr obji = (quintptr) object;
  if (p->refInfos.contains(obji)) {
    klfDbg(klfFmtCC("Object destroyed: (%s*)%p; object reference name is `%s'",
		    (object ? object->metaObject()->className() : "void"),
		    object, qPrintable(p->refInfos[obji])));
  } else {
    klfDbg(klfFmtCC("Object destroyed: (%s*)%p",
		    (object ? object->metaObject()->className() : "void"),
		    object));
  }
}
void KLFUnitSpinBox::setUnit(double unitfactor)
{
  double curValue = value();
  double curMinimum = minimum();
  double curMaximum = maximum();
  double curUnitFactor = pUnitFactor;
  int curPrecision = decimals();

  klfDbg("unitfactor="<<unitfactor<<" cur: val="<<curValue<<",min="<<curMinimum<<",max="<<curMaximum
	 <<",prec="<<curPrecision) ;

  pUnitFactor = unitfactor;

  // calculate the right number of decimal places.
  // due to round-off errors, we need to first determine how many decimals we started
  // off with, then re-calculate the number of decimals.
  int unitRefDecimals = curPrecision - (int)( log((double)curUnitFactor)/log((double)10.0)  + 0.5 );

  setDecimals(unitRefDecimals + (int)( log((double)pUnitFactor)/log((double)10.0) + 0.5 ) );

  // set the appropriate range
  setMinimum(curMinimum * curUnitFactor / pUnitFactor);
  setMaximum(curMaximum * curUnitFactor / pUnitFactor);

  // and set the value
  setValue(curValue * curUnitFactor / pUnitFactor);
}
Exemplo n.º 5
0
bool SysTrayIconPlugin::eventFilter(QObject *obj, QEvent *e)
{
  if (obj == _systrayicon && e->type() == QEvent::ToolTip) {
    // works on X11 only
    if (_config->readValue("restoreonhover").toBool()) {
      restore();
    }
  }

  //#ifndef KLF_MAC_HIDE_INSTEAD ... well yes do this too, except by default disable this option
  if (obj == _mainwin && e->type() == QEvent::WindowStateChange) {
    if ( _mainwin->property("x11WindowShaded").toBool() )
      return false; // don't take action if the window is just shaded

    klfDbg("main win window state changed: oldState="<<((QWindowStateChangeEvent*)e)->oldState()
	   <<" new state="<<_mainwin->windowState()) ;
    if ( _config->readValue("systrayon").toBool() &&
	 _config->readValue("mintosystray").toBool() &&
	(_mainwin->windowState() & Qt::WindowMinimized) &&
	!(((QWindowStateChangeEvent*)e)->oldState() & Qt::WindowMinimized)
	) {
      // the user minimized the window, and we want to minimize it to system tray.
      QTimer::singleShot(20, this, SLOT(minimize()));
    }
  }
  //#endif // KLF_MAC_HIDE_INSTEAD

  return false;
}
Exemplo n.º 6
0
bool KLFBlockProcess::startProcess(QStringList cmd, QByteArray stdindata, QStringList env)
{
  klfDbg("Running: "<<cmd<<", stdindata/size="<<stdindata.size());

  _runstatus = 0;

  KLF_ASSERT_CONDITION(cmd.size(), "Empty command list given.", return false;) ;
void KLFLibEntryEditor::slotApplyChanges(bool cat, bool tags)
{
  klfDbg("category="<<cat<<" tags="<<tags) ;
  QMap<int,QVariant> data;
  if (cat && u->cbxCategory->isEnabled()) {
    slotCbxSaveCurrentCompletion(u->cbxCategory);
    data[KLFLibEntry::Category] = u->cbxCategory->currentText();
  }
  if (tags && u->cbxTags->isEnabled()) {
    slotCbxSaveCurrentCompletion(u->cbxTags);
    data[KLFLibEntry::Tags] = u->cbxTags->currentText();
  }
  klfDbg("data to update: "<<data) ;
  if (data.isEmpty())
    return;

  emit metaInfoChanged(data);
}
void KLFUnitChooser::internalCurrentIndexChanged(int index)
{
  if (index < 0 || index >= count())
    return;

  Unit u = itemData(index).value<Unit>();
  klfDbg("New unit selected : #"<<index<<" = "<<u.name) ;
  emit unitChanged(u.name);
  emit unitChanged(u.factor);
  emit unitChanged(u.factor, u.abbrev);
}
Exemplo n.º 9
0
void SysTrayIconPlugin::restore()
{
  KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
  if (!isMinimized() || !_config->readValue("systrayon").toBool())
    return;

  klfDbg("debug... restoring.") ;
  klfRestoreWindows();
  _mainwin->raise();
  _mainwin->activateWindow();
  qApp->alert(_mainwin);
}
Exemplo n.º 10
0
// static
QMimeData *KLFAbstractLibEntryMimeEncoder::createMimeData(const KLFLibEntryList& entryList,
							  const QVariantMap& metaData)
{
  QMimeData *mime = new QMimeData;
  int k, j;
  for (k = 0; k < staticEncoderList.size(); ++k) {
    QStringList mimeTypeList = staticEncoderList[k]->supportedEncodingMimeTypes();
    for (j = 0; j < mimeTypeList.size(); ++j) {
      QByteArray data =
	staticEncoderList[k]->encodeMime(entryList, metaData, mimeTypeList[j]);
      if (data.isEmpty()) {
	klfDbg("Skipping mime type "<<mimeTypeList[k]<<" because it did not provide any data.");
      } else {
	mime->setData(mimeTypeList[j], data);
      }
    }
  }
  return mime;
}
Exemplo n.º 11
0
KLF_EXPORT QStringList klfSearchFind(const QString& wildcard_expression, int limit)
{
  klfDbg("looking for "+wildcard_expression) ;

  QString expr;
#ifdef KLFBACKEND_QT4
  expr = QDir::fromNativeSeparators(wildcard_expression);
#else
  expr = wildcard_expression;  expr.replace(QDir::separator(), "/");
#endif
  QStringList pathlist = str_split(expr, "/", false);
  QString root = "/";
  static QRegExp driveregexp("^[A-Za-z]:$");
  if (driveregexp.exactMatch(pathlist[0])) {
    // Windows System with X: drive letter
    root = pathlist[0]+"/";
    pathlist.pop_front();
  }
  return __search_find_test(root, pathlist, 0, limit);
}
Exemplo n.º 12
0
static bool is_binary_file(QString fn)
{
  if (!QFile::exists(fn)) {
    fn = klfSearchPath(fn);
  }
  QFile fpeek(fn);
  if (!fpeek.open(QIODevice::ReadOnly)) {
    klfDbg("fn="<<fn<<", Can't peek into file "<<fn<<"!") ;
  } else {
    QByteArray line;
    int n = 0, j;
    while (n++ < 3 && (line = fpeek.readLine()).size()) {
      for (j = 0; j < line.size(); ++j) {
        if ((int)line[j] >= 127 || (int)line[j] <= 0) {
          return true;
        }
      }
    }
    return false;
  }
  return false;
}
void KLFUnitSpinBox::internalValueChanged(double valueInExtUnits)
{
  klfDbg("val in ext. units="<<valueInExtUnits<<"; our unitfactor="<<pUnitFactor) ;
  emit valueInRefUnitChanged(valueInExtUnits / pUnitFactor);
}
Exemplo n.º 14
0
// static
Skin SkinConfigWidget::loadSkin(KLFPluginConfigAccess * config, const QString& fn, bool getstylesheet)
{
  Q_UNUSED(getstylesheet) ;
  KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
  klfDbg("loading skin "<<fn<<", get style sheet="<<getstylesheet) ;

  Skin skin;

  skin.fn = fn;

  QFile f(fn);
  if ( ! f.open(QIODevice::ReadOnly) ) {
    qWarning()<<KLF_FUNC_NAME<<": Can't read skin "<<fn<<"!";
    return skin;
  }

  QDomDocument doc("klf-skin");
  QString errMsg; int errLine, errCol;
  bool r = doc.setContent(&f, false, &errMsg, &errLine, &errCol);
  if (!r) {
    qWarning()<<KLF_FUNC_NAME<<": Error parsing file "<<fn<<": "<<errMsg<<" at line "<<errLine<<", col "<<errCol;
    return skin;
  }
  f.close();

  QDomElement root = doc.documentElement();
  if (root.nodeName() != "klf-skin") {
    qWarning("%s: Error parsing XML for skin `%s': Bad root node `%s'.\n",
	     KLF_FUNC_NAME, qPrintable(fn), qPrintable(root.nodeName()));
    return skin;
  }

  QMap<QString,QString> defines;

  QStringList stylesheetpath = QStringList()
    << QLatin1String(":/plugindata/skin/stylesheets")
    << config->homeConfigPluginDataDir() + "/stylesheets";

  // read XML file
  QDomNode n;
  for (n = root.firstChild(); ! n.isNull(); n = n.nextSibling()) {
    QDomElement e = n.toElement(); // try to convert the node to an element.
    if ( e.isNull() || n.nodeType() != QDomNode::ElementNode )
      continue;
    if ( e.nodeName() == "name" ) {
      skin.name = qApp->translate("xmltr_pluginskins", e.text().toUtf8().constData(),
				  "[[tag: <name>]]", QCoreApplication::UnicodeUTF8);
      continue;
    } else if ( e.nodeName() == "author" ) {
      skin.author = e.text();
      continue;
    } else if ( e.nodeName() == "def" ) {
      QString key = e.attribute("name");
      QString value = e.text();
      if (QRegExp("^[A-Za-z][A-Za-z0-9_]*$").exactMatch(key))
	defines[key] = value;
      else
	qWarning()<<KLF_FUNC_NAME<<": file "<<fn<<": Illegal <def> name: "<<key;
    } else if ( e.nodeName() == "description" ) {
      skin.description = qApp->translate("xmltr_pluginskins", e.text().toUtf8().constData(),
				  "[[tag: <description>]]", QCoreApplication::UnicodeUTF8);
      continue;
    } else if ( e.nodeName() == "stylesheet" ) {
      QString fnqssbase = e.text().trimmed();
      QString fnqss = klfSearchPath(fnqssbase, stylesheetpath);
      QFile fqss(fnqss);
      if (fnqss.isEmpty() || !fqss.exists() || !fqss.open(QIODevice::ReadOnly)) {
	qWarning()<<KLF_FUNC_NAME<<"Can't open qss-stylesheet file "<<fnqssbase
		  <<" while reading skin "<<fn<<".";
	continue;
      }
      QString ss = QString::fromUtf8(fqss.readAll());
      if (!defines.isEmpty()) {
	// we need to process <def>ines ...
	QRegExp alldefines_rx = QRegExp("\\b("+QStringList(defines.keys()).join("|")+")\\b");
	int k = 0;
	while ( (k = alldefines_rx.indexIn(ss, k+1)) != -1) {
	  QString key = alldefines_rx.cap(1);
	  KLF_ASSERT_CONDITION( defines.contains(key), "Error: key "<<key<<" found, but not in defines="
				<<defines<<"?!?",   ++k; continue; ) ;
	  QString value = defines[key];
	  klfDbg("Substituting def. "<<key<<" by "<<value<<" in style sheet "<<fnqss<<" for "<<fn) ;
	  ss.replace(k, alldefines_rx.matchedLength(), value);
	  k += value.length();
	}
	klfDbg("def-Replaced style sheet is \n"<<ss) ;
      }