Exemplo n.º 1
0
 ~Private()
 {
     if (qgetenv("XDG_CURRENT_DESKTOP") == "GNOME") {
         useStaticForNative = true;
         QClipboard *cb = QApplication::clipboard();
         cb->blockSignals(false);
     }
 }
Exemplo n.º 2
0
    Private(QWidget *parent_,
            KoFileDialog::DialogType dialogType_,
            const QString caption_,
            const QString defaultDir_,
            const QString dialogName_)
        : parent(parent_)
        , type(dialogType_)
        , dialogName(dialogName_)
        , caption(caption_)
        , defaultDirectory(defaultDir_)
        , filterList(QStringList())
        , defaultFilter(QString())
        , useStaticForNative(false)
        , hideDetails(false)
        , swapExtensionOrder(false)
    {
        // Force the native file dialogs on Windows. Except for KDE, the native file dialogs are only possible
        // using the static methods. The Qt documentation is wrong here, if it means what it says " By default,
        // the native file dialog is used unless you use a subclass of QFileDialog that contains the Q_OBJECT
        // macro."
#ifdef Q_OS_WIN
        useStaticForNative = true;
#endif
        // Non-static KDE file is broken when called with QFileDialog::AcceptSave:
        // then the directory above defaultdir is opened, and defaultdir is given as the default file name...
        //
        // So: in X11, use static methods inside KDE, which give working native dialogs, but non-static outside
        // KDE, which gives working Qt dialogs.
        //
        // Only show the GTK dialog in Gnome, where people deserve it
#ifdef HAVE_X11
        if (qgetenv("KDE_FULL_SESSION").size() > 0) {
            useStaticForNative = true;
        }
        if (qgetenv("XDG_CURRENT_DESKTOP") == "GNOME") {
            useStaticForNative = true;
            QClipboard *cb = QApplication::clipboard();
            cb->blockSignals(true);
            swapExtensionOrder = true;
        }

#endif
    }
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  int action;
  double timeout = 5.;
  int argIndex, numArgs;
  int interval;
  char *endptr;
  QString qstr;
  QTime curTime = QTime::currentTime();
  int timeStamp = 60000 * curTime.minute() + 1000 * curTime.second() +
    curTime.msec();

  for (argIndex = 1; argIndex < argc - 1 ; argIndex++) {
    if (argv[argIndex][0] == '-'){
      switch (argv[argIndex][1]){
        
      case 't': /* timeout interval */
        timeout = strtod(argv[++argIndex], &endptr);
        if (endptr - argv[argIndex] < (int)strlen(argv[argIndex])) {
          fprintf(stderr, "ERROR: imodsendevent - invalid timeout entry %s\n",
                  argv[argIndex]);
          exit(3);
        }
        break;

      case 'D': /* debug */
        debugOut = 1;
        break;

      default:
        fprintf(stderr, "ERROR: imodsendevent - invalid argument %s\n",
                argv[argIndex]);
        exit(3);
        break;
      } 
    } else
      break;
  }

  numArgs = argc - argIndex;

  if (numArgs < 2) {
    fprintf(stderr, "ERROR: imodsendevent - Wrong number of arguments\n"
            "   Usage: imodsendevent [-t timeout] [-D] Window_ID action "
            "[arguments]\n");
    exit(3);
  }

  // Check the arguments for odd characters
  winID = strtol(argv[argIndex], &endptr, 10);
  if (endptr - argv[argIndex] < (int)strlen(argv[argIndex])) {
    fprintf(stderr, "ERROR: imodsendevent - invalid characters in window ID"
            " entry %s\n", argv[argIndex]);
    exit(3);
  }
  action = strtol(argv[argIndex + 1], &endptr, 10);
  if (endptr - argv[argIndex + 1] < (int)strlen(argv[argIndex + 1])) {
    fprintf(stderr, "ERROR: imodsendevent - invalid characters in action "
            "entry %s\n", argv[argIndex + 1]);
    exit(3);
  }

  // Create the application
  ImodSendEvent a(argc, argv);
  setlocale(LC_NUMERIC, "C");

  // Pack the arguments into a QString
  timeStr.sprintf(" %d ", timeStamp);
  timeStr = QString(argv[argIndex]) + timeStr; 
  cmdStr = QString(argv[argIndex + 1]);
  for (; argIndex + 2 < argc; argIndex++)
    cmdStr += QString(" ") + QString(argv[argIndex + 2]);
  qstr = timeStr + cmdStr;

  // Connect to the clipboard, start the timeout, and send the text
  QClipboard *cb = QApplication::clipboard();

  // Default for setText and text() is Clipboard mode
  //cb->setSelectionMode(false);
  cb->blockSignals(true);
  QObject::connect(cb, SIGNAL(dataChanged()), &a, SLOT(clipboardChanged()));
  cb->blockSignals(false);

  // Start a timeout timer if the interval is not zero.
  interval = (int)(1000. * timeout + 0.5);
  if (interval > 0) {

    // If this hack is defined and > 0, divide the total timeout into intervals 
    // of this length and retry sending message
#ifdef SENDEVENT_RETRY_HACK
    if (SENDEVENT_RETRY_HACK > 0) {
      retryLimit = interval / SENDEVENT_RETRY_HACK;
      if (!retryLimit)
        retryLimit = 1;
      interval = SENDEVENT_RETRY_HACK;
    }
#endif
    a.startTimer(interval);
  }

  if (debugOut)
    fprintf(stderr, "Imodsendevent sending: %s\n", LATIN1(qstr));
  cb->setText(qstr);

  // If the hack is defined as zero, just process events and set the text again
#ifdef SENDEVENT_RETRY_HACK
  if (SENDEVENT_RETRY_HACK == 0) {
    qApp->processEvents();
    cb->setText(qstr);
  }
#endif

  return a.exec();

}