Ejemplo n.º 1
0
NErrorWhileDialog::NErrorWhileDialog(const QStringList& args,
                                     const QString& errmsg,
                                     const int errcode,
                                     QWidget *parent)
  : QDialog(parent)
{
  QVBoxLayout *box = new QVBoxLayout;

// Label

  QLabel *l = new QLabel(label(ErrorWhileRunning));
  box->addWidget(l);

// Command args

  QPlainTextEdit *t = new QPlainTextEdit(this);
  t->setPlainText(args.join(" "));
  t->setReadOnly(true);
  box->addWidget(t);

// Label

  l = new QLabel(label(ErrorMessageFollows));
  box->addWidget(l);

// Error message

  t = new QPlainTextEdit(this);
  const QString s = label(ErrorCode, QString("%1").arg(errcode));
  t->setPlainText(QString("%1\n%2").arg(errmsg).arg(s));
  t->setReadOnly(true);
  box->addWidget(t);

// Button box

  QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
  QPushButton *b = new QPushButton(tr("Co&py"));
  b->setToolTip(tr("Copy to clipboard"));

  bb->addButton(b, QDialogButtonBox::ActionRole);

  connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
  connect(b, SIGNAL(clicked()), this, SLOT(copy()));
  box->addWidget(bb);

// Window

  setFixedSize(QSize(400,340));
  setWindowTitle(tr("Error"));
  setLayout(box);
  show();

// Save

  _errcode = errcode;
  _errmsg = errmsg;
  _args = args;
}
Ejemplo n.º 2
0
void DevConsole::logToConsole(const QString &logText, const QString &channel, bool raise)
{
    for(int i = 0; i < ui->tabWidget->count(); ++i){
        if(ui->tabWidget->tabText(i)==channel){
            QPlainTextEdit* tarEdit = getEditByIndex(i);
            if(!tarEdit)
                return;
            tarEdit->appendPlainText(logText);
            tarEdit->verticalScrollBar()->setValue(tarEdit->verticalScrollBar()->maximum());
            if(raise) ui->tabWidget->setCurrentIndex(i);
            return;
        }
    }
    //create new channel
    QWidget* w = new QWidget();
    QGridLayout *l = new QGridLayout(w);
    l->setContentsMargins(0, 0, 0, 0);
    l->setSpacing(0);
    QPlainTextEdit *e = new QPlainTextEdit(w);
    l->addWidget(e,0,0,1,1);
    QPushButton *p = new QPushButton(w);
    l->addWidget(p,1,0,1,1);
    connect(p, SIGNAL(clicked()), this, SLOT(clearCurrentLog()));
    p->setText(tr("Clear %1 Log").arg(channel));
    e->setReadOnly(true);
    e->appendPlainText(logText);
    e->verticalScrollBar()->setValue(e->verticalScrollBar()->maximum());
    ui->tabWidget->addTab(w,channel);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  QApplication app(argc, argv);

    // Load the Periodic Table translations
    QPointer <QTranslator> ptTranslator = QPeriodicTable::createTranslator();
    if (ptTranslator)
      qApp->installTranslator(ptTranslator);

  // Construct Periodic Table
  PeriodicTableView* periodicTable = new PeriodicTableView;
  periodicTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  QMainWindow *window = new QMainWindow();
  window->setWindowTitle("Periodic System of D.I.Mendeleyev");
  QWidget *widget = new QWidget;
  QHBoxLayout *layout = new QHBoxLayout(widget);
  widget->setLayout(layout);
  QPlainTextEdit *elementInfo = new QPlainTextEdit;
  elementInfo->setReadOnly(true);
  elementInfo->setPlainText("Click on element to get the information about it");
  elementInfo->setMaximumHeight(periodicTable->height());
  elementInfo->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
  layout->addWidget(periodicTable);
  layout->addWidget(elementInfo);
  window->setCentralWidget(widget);
  PeriodicTableWatcher *watcher = new PeriodicTableWatcher(periodicTable, elementInfo);
  window->show();
  app.exec();
  delete periodicTable;
  delete elementInfo;
  delete window;
  return 0;
}
Ejemplo n.º 4
0
void QmlEngine::gotoLocation(const Location &location)
{
    const QString fileName = location.fileName();
    if (QUrl(fileName).isLocalFile()) {
        // internal file from source files -> show generated .js
        QTC_ASSERT(m_sourceDocuments.contains(fileName), return);

        QString titlePattern = tr("JS Source for %1").arg(fileName);
        //Check if there are open documents with the same title
        foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) {
            if (document->displayName() == titlePattern) {
                Core::EditorManager::activateEditorForDocument(document);
                return;
            }
        }
        Core::IEditor *editor = Core::EditorManager::openEditorWithContents(
                    QmlJSEditor::Constants::C_QMLJSEDITOR_ID, &titlePattern);
        if (editor) {
            editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true);
            QPlainTextEdit *plainTextEdit =
                    qobject_cast<QPlainTextEdit *>(editor->widget());
            if (plainTextEdit)
                plainTextEdit->setReadOnly(true);
            updateDocument(editor->document(), m_sourceDocuments.value(fileName));
        }
    } else {
Ejemplo n.º 5
0
        void catchException(const std::exception& ex) {
            QString error = QString::fromUtf8(ex.what());
            QString message = "<qt><b>qtfuzzylite</b> has experienced an internal error and will exit.<br><br>"
                    "Please report this error to &nbsp; <a href='mailto:[email protected]'>"
                    "[email protected]</a><br><br>"
                    "Your report will help to make <b>fuzzylite</b> and <b>qtfuzzylite</b> a better "
                    "free open source fuzzy logic library!<br><br>"
                    "Many thanks in advance for your help!"
                    "</qt>";
            QMessageBox x(NULL);
            x.setText(message);
            x.setWindowTitle("Internal Error");
            x.setIcon(QMessageBox::Critical);
            QLabel dummy;
            x.layout()->addWidget(&dummy);

            QLabel viewLabel("Error message:");
            QPlainTextEdit viewError;
            viewError.setReadOnly(true);
            viewError.setPlainText(error);
            viewError.setLineWrapMode(QPlainTextEdit::NoWrap);
            QFont tt("?");
            tt.setStyleHint(QFont::TypeWriter);
            tt.setPointSize(tt.pointSize() - 2);
            viewError.setFont(tt);

            QWidget* view = new QWidget;
            view->setLayout(new QVBoxLayout);
            view->layout()->addWidget(&viewLabel);
            view->layout()->addWidget(&viewError);
            x.layout()->addWidget(view);
            x.exec();
        }
Ejemplo n.º 6
0
FriendRequestDialog::FriendRequestDialog(QWidget *parent, const QString &userId, const QString &message) :
    QDialog(parent)
{
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    setWindowTitle("Friend request");

    QLabel *friendsLabel = new QLabel("Someone wants to make friends with you.", this);
    QLabel *userIdLabel = new QLabel("User ID:", this);
    QLineEdit *userIdEdit = new QLineEdit(userId, this);
    userIdEdit->setReadOnly(true);
    QLabel *messageLabel = new QLabel("Friend request message:", this);
    QPlainTextEdit *messageEdit = new QPlainTextEdit(message, this);
    messageEdit->setReadOnly(true);


    QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);

    buttonBox->addButton("Accept", QDialogButtonBox::AcceptRole);
    buttonBox->addButton("Reject", QDialogButtonBox::RejectRole);

    connect(buttonBox, &QDialogButtonBox::accepted, this, &FriendRequestDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &FriendRequestDialog::reject);

    QVBoxLayout *layout = new QVBoxLayout(this);

    layout->addWidget(friendsLabel);
    layout->addSpacing(12);
    layout->addWidget(userIdLabel);
    layout->addWidget(userIdEdit);
    layout->addWidget(messageLabel);
    layout->addWidget(messageEdit);
    layout->addWidget(buttonBox);

    resize(300, 200);
}
Ejemplo n.º 7
0
QList<RewriterView::Error> DesignDocumentController::loadMaster(const QByteArray &qml)
{
    QPlainTextEdit *textEdit = new QPlainTextEdit;
    textEdit->setReadOnly(true);
    textEdit->setPlainText(QString(qml));
    return loadMaster(textEdit);
}
Ejemplo n.º 8
0
void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level )
{
  QString cleanedTag = tag;
  if ( cleanedTag.isNull() )
    cleanedTag = tr( "General" );

  int i;
  for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ).remove( QChar( '&' ) ) != cleanedTag; i++ );

  QPlainTextEdit *w = nullptr;
  if ( i < tabWidget->count() )
  {
    w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
    tabWidget->setCurrentIndex( i );
  }
  else
  {
    w = new QPlainTextEdit( this );
    w->setReadOnly( true );
    tabWidget->addTab( w, cleanedTag );
    tabWidget->setCurrentIndex( tabWidget->count() - 1 );
  }

  QString levelString;
  QgsSettings settings;
  QColor color;
  switch ( level )
  {
    case Qgis::Info:
      levelString = QStringLiteral( "INFO" );
      color = QColor( settings.value( QStringLiteral( "colors/info" ), QStringLiteral( "#000000" ) ).toString() );
      break;
    case Qgis::Warning:
      levelString = QStringLiteral( "WARNING" );
      color = QColor( settings.value( QStringLiteral( "colors/warning" ), QStringLiteral( "#000000" ) ).toString() );
      break;
    case Qgis::Critical:
      levelString = QStringLiteral( "CRITICAL" );
      color = QColor( settings.value( QStringLiteral( "colors/critical" ), QStringLiteral( "#000000" ) ).toString() );
      break;
    case Qgis::Success:
      levelString = QStringLiteral( "SUCCESS" );
      color = QColor( settings.value( QStringLiteral( "colors/success" ), QStringLiteral( "#000000" ) ).toString() );
      break;
    case Qgis::None:
      levelString = QStringLiteral( "NONE" );
      color = QColor( settings.value( QStringLiteral( "colors/default" ), QStringLiteral( "#000000" ) ).toString() );
      break;
  }

  QString prefix = QStringLiteral( "<font color=\"%1\">%2 &nbsp;&nbsp;&nbsp; %3 &nbsp;&nbsp;&nbsp;</font>" )
                   .arg( color.name(), QDateTime::currentDateTime().toString( Qt::ISODate ), levelString );
  QString cleanedMessage = message;
  cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" ) );
  w->appendHtml( cleanedMessage );
  w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
}
Ejemplo n.º 9
0
void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
{
  QString cleanedTag = tag;
  if ( cleanedTag.isNull() )
    cleanedTag = tr( "General" );

  int i;
  for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != cleanedTag; i++ )
    ;

  QPlainTextEdit *w = nullptr;
  if ( i < tabWidget->count() )
  {
    w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
    tabWidget->setCurrentIndex( i );
  }
  else
  {
    w = new QPlainTextEdit( this );
    w->setReadOnly( true );
    tabWidget->addTab( w, cleanedTag );
    tabWidget->setCurrentIndex( tabWidget->count() - 1 );
    tabWidget->setTabsClosable( true );
  }

  QString levelString;
  switch ( level )
  {
    case QgsMessageLog::INFO:
      levelString = "INFO";
      break;
    case QgsMessageLog::WARNING:
      levelString = "WARNING";
      break;
    case QgsMessageLog::CRITICAL:
      levelString = "CRITICAL";
      break;
    case QgsMessageLog::NONE:
      levelString = "NONE";
      break;
  }

  QString prefix = QStringLiteral( "%1\t%2\t" )
                   .arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
                   .arg( levelString );
  QString cleanedMessage = message;
  cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "\n\t\t\t" ) );
  w->appendPlainText( cleanedMessage );
  w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
}
Ejemplo n.º 10
0
HexDumpWindow::HexDumpWindow(QString romFilePath, QWidget * parent) : QWidget(parent, Qt::Window)
{
	this->setWindowTitle(tr("Hex Dump"));

	QString dump = QString::fromStdString(disassembler::RomParser::hexDump(romFilePath.toStdString()));
	QPlainTextEdit* editor = new QPlainTextEdit(dump);
	editor->setFont(QFont ("Courier", 11));
	editor->setReadOnly(true);

	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(editor);

	this->setLayout(layout);
	this->setFixedSize(600, 600);
}
Ejemplo n.º 11
0
DebugWidget::DebugWidget()
{
    this->setWindowTitle("Debug Log");
    this->setAttribute( Qt::WA_QuitOnClose, false ); //quit only when main window is closed
    QBoxLayout* layout = new QVBoxLayout();
    this->setLayout(layout);
    QPlainTextEdit *textEdit = new QPlainTextEdit(this);
    QFont font = QFont("Monospace");
    font.setStyleHint(QFont::TypeWriter);
    textEdit->setFont(font);
    textEdit->setReadOnly(true);
    layout->addWidget(textEdit);
    this->show();
    DEBUG_DISPLAY = textEdit;
}
db_error_dialog::db_error_dialog(const QString error) : m_error_text(error)
{
  setWindowTitle(tr("Database error"));
  QVBoxLayout* layout = new QVBoxLayout(this);

  setMinimumWidth(400);		// reasonable minimum

  QPlainTextEdit* label = new QPlainTextEdit;
  label->setPlainText(error);
  label->setReadOnly(true);
  label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
  label->setFrameShape(QFrame::Box);
  label->setFrameShadow(QFrame::Raised);
  layout->addWidget(label);

  m_btn_group = new QButtonGroup(this);
  QButtonGroup* g = m_btn_group;

  QRadioButton* btn1 = new QRadioButton(tr("Continue"));
  g->addButton(btn1, 1);
  btn1->setChecked(true);

  QRadioButton* btn2 = new QRadioButton(tr("Try to reconnect"));
  g->addButton(btn2, 2);

  QRadioButton* btn3 = new QRadioButton(tr("Quit application"));
  g->addButton(btn3, 3);

  layout->addWidget(btn1);
  layout->addWidget(btn2);
  layout->addWidget(btn3);

  QPushButton* btn_OK = new QPushButton(tr("OK"));
  btn_OK->setDefault(true);

  QPushButton* copy_btn = new QPushButton(tr("Copy"));

  QDialogButtonBox* buttonBox = new QDialogButtonBox(Qt::Horizontal);
  buttonBox->addButton(copy_btn, QDialogButtonBox::ActionRole);
  buttonBox->addButton(btn_OK, QDialogButtonBox::AcceptRole);
  layout->addWidget(buttonBox);
  connect(copy_btn, SIGNAL(clicked()), this, SLOT(copy_error()));
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  connect(this, SIGNAL(accepted()), this, SLOT(handle_error()));
}
Ejemplo n.º 13
0
int main(int argc, char ** argv) {
   QApplication app{argc, argv};
   WhatsThisSignaler sig;
   QPlainTextEdit w;
   w.setWindowFlags(Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint);
   w.setMinimumSize(200, 200);
   w.setReadOnly(true);
   w.show();
   sig.installOn(&w);
   QObject::connect(&sig, &WhatsThisSignaler::whatsThisEvent, &w, [&w](QWidget*widget, QEvent*ev){
      w.appendPlainText(QStringLiteral("%1(0x%2) \"%3\" QEvent::%4")
                        .arg(widget->metaObject()->className())
                        .arg((uintptr_t)widget, 0, 16)
                        .arg(widget->objectName())
                        .arg(toName(ev->type())));
   });
   return app.exec();
}
Ejemplo n.º 14
0
ScriptLogWindow::ScriptLogWindow() : QWidget(nullptr)
{
	const QFont fixedFont =
		QFontDatabase::systemFont(QFontDatabase::FixedFont);

	QPlainTextEdit *edit = new QPlainTextEdit();
	edit->setReadOnly(true);
	edit->setFont(fixedFont);
	edit->setWordWrapMode(QTextOption::NoWrap);

	QHBoxLayout *buttonLayout = new QHBoxLayout();
	QPushButton *clearButton = new QPushButton(tr("Clear"));
	connect(clearButton, &QPushButton::clicked,
			this, &ScriptLogWindow::ClearWindow);
	QPushButton *closeButton = new QPushButton(tr("Close"));
	connect(closeButton, &QPushButton::clicked,
			this, &QDialog::hide);

	buttonLayout->addStretch();
	buttonLayout->addWidget(clearButton);
	buttonLayout->addWidget(closeButton);

	QVBoxLayout *layout = new QVBoxLayout();
	layout->addWidget(edit);
	layout->addLayout(buttonLayout);

	setLayout(layout);
	scriptLogWidget = edit;

	resize(600, 400);

	config_t *global_config = obs_frontend_get_global_config();
	const char *geom = config_get_string(global_config,
			"ScriptLogWindow", "geometry");
	if (geom != nullptr) {
		QByteArray ba = QByteArray::fromBase64(QByteArray(geom));
		restoreGeometry(ba);
	}

	setWindowTitle(obs_module_text("ScriptLogWindow"));

	connect(edit->verticalScrollBar(), &QAbstractSlider::sliderMoved,
			this, &ScriptLogWindow::ScrollChanged);
}
Ejemplo n.º 15
0
About::About(QWidget * parent, Qt::WindowFlags f)
   : QDialog(parent, f)
{
   // stuff
   setWindowTitle("About LibreLibreCell");

   QLabel *versionLabel = new QLabel(QString("Git revision: %1").arg(LIBRELIBRECELL_VERSION));
   QPlainTextEdit *aboutBox = new QPlainTextEdit;
   QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);

   QVBoxLayout *vLayout = new QVBoxLayout;
   vLayout->addWidget(versionLabel);
   vLayout->addWidget(aboutBox, 1);
   vLayout->addSpacing(10);
   vLayout->addWidget(buttonBox);

   setLayout(vLayout);


   aboutBox->setReadOnly(true);
   aboutBox->setTabChangesFocus(true);
   aboutBox->setWordWrapMode(QTextOption::NoWrap);
   aboutBox->setLineWrapMode(QPlainTextEdit::NoWrap);
   aboutBox->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   aboutBox->setFont(QFont("Monospace", 10));

   QFile readme(":/README.txt");
   if (readme.open(QIODevice::ReadOnly))
   {
      QTextStream stream(&readme);
      aboutBox->setPlainText(stream.readAll());
      readme.close();
   }
   else
   {
      aboutBox->setPlainText("Could not open README.txt.");
   }
   QFontMetrics fm(aboutBox->font());
   aboutBox->setMinimumSize(fm.width(QLatin1Char('m')) * 76, 450);

   connect(buttonBox, SIGNAL(accepted()),
               this, SLOT(accept()));
}
Ejemplo n.º 16
0
void QgsMessageLogViewer::logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level )
{
#ifdef ANDROID
  mButton->setToolTip( tr( "Message(s) logged." ) );
#endif

  if ( !isVisible() && level > QgsMessageLog::INFO )
  {
    mButton->show();
    if ( mShowToolTips )
      QToolTip::showText( mButton->mapToGlobal( QPoint( 0, 0 ) ), mButton->toolTip() );
  }

  if ( tag.isNull() )
    tag = tr( "General" );

  int i;
  for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != tag; i++ )
    ;

  QPlainTextEdit *w;
  if ( i < tabWidget->count() )
  {
    w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) );
    tabWidget->setCurrentIndex( i );
  }
  else
  {
    w = new QPlainTextEdit( this );
    w->setReadOnly( true );
    tabWidget->addTab( w, tag );
    tabWidget->setCurrentIndex( tabWidget->count() - 1 );
  }

  QString prefix = QString( "%1\t%2\t")
                       .arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
                       .arg( level );
  w->appendPlainText( message.prepend( prefix ).replace( "\n", "\n\t\t\t" ) );
  w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() );
}
Ejemplo n.º 17
0
void DevConsole::logToConsole(const QString &logText, const QString &channel, bool raise)
{
    QString target_channel = channel;

    if(channel == "System") //Prevent creation another "system" tab if switched another UI language
        target_channel = ui->tabWidget->tabText(0);

    for(int i = 0; i < ui->tabWidget->count(); ++i)
    {
        if(ui->tabWidget->tabText(i) == target_channel)
        {
            QPlainTextEdit *tarEdit = getEditByIndex(i);
            if(!tarEdit)
                return;
            tarEdit->appendPlainText(logText);
            tarEdit->verticalScrollBar()->setValue(tarEdit->verticalScrollBar()->maximum());
            if(raise) ui->tabWidget->setCurrentIndex(i);
            return;
        }
    }
    //create new channel
    QWidget *w = new QWidget();
    QGridLayout *l = new QGridLayout(w);
    l->setContentsMargins(0, 0, 0, 0);
    l->setSpacing(0);
    QPlainTextEdit *e = new QPlainTextEdit(w);
    l->addWidget(e, 0, 0, 1, 1);
    QPushButton *p = new QPushButton(w);
    l->addWidget(p, 1, 0, 1, 1);
    p->setFlat(true);
    p->connect(p, SIGNAL(clicked()), this, SLOT(clearCurrentLog()));
    p->setText(tr("Clear %1 Log").arg(target_channel));
    e->setReadOnly(true);
    e->setStyleSheet(ui->plainTextEdit->styleSheet());
    e->setFont(ui->plainTextEdit->font());
    e->appendPlainText(logText);
    e->verticalScrollBar()->setValue(e->verticalScrollBar()->maximum());
    ui->tabWidget->addTab(w, target_channel);
}
Ejemplo n.º 18
0
ConfigurationDialog::ConfigurationDialog(QWidget *parent) : KPageDialog(parent)
{
	setCaption(i18nc("@title:window", "Configure Kaffeine"));

	QWidget *widget = new QWidget(this);
	QGridLayout *gridLayout = new QGridLayout(widget);

	startupDisplayModeBox = new KComboBox(widget);
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Normal Mode"));
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Minimal Mode"));
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Full Screen Mode"));
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Remember Last Setting"));
	startupDisplayModeBox->setCurrentIndex(Configuration::instance()->getStartupDisplayMode());
	gridLayout->addWidget(startupDisplayModeBox, 0, 1);

	QLabel *label = new QLabel(i18nc("@label:listbox", "Startup display mode:"), widget);
	label->setBuddy(startupDisplayModeBox);
	gridLayout->addWidget(label, 0, 0);

	shortSkipBox = new QSpinBox(widget);
	shortSkipBox->setRange(1, 600);
	shortSkipBox->setValue(Configuration::instance()->getShortSkipDuration());
	gridLayout->addWidget(shortSkipBox, 1, 1);

	label = new QLabel(i18nc("@label:spinbox", "Short skip duration:"), widget);
	label->setBuddy(shortSkipBox);
	gridLayout->addWidget(label, 1, 0);

	longSkipBox = new QSpinBox(widget);
	longSkipBox->setRange(1, 600);
	longSkipBox->setValue(Configuration::instance()->getLongSkipDuration());
	gridLayout->addWidget(longSkipBox, 2, 1);

	label = new QLabel(i18nc("@label:spinbox", "Long skip duration:"), widget);
	label->setBuddy(longSkipBox);
	gridLayout->addWidget(label, 2, 0);
	gridLayout->setRowStretch(3, 1);

	KPageWidgetItem *page = new KPageWidgetItem(widget, i18nc("@title:group", "General"));
	page->setIcon(KIcon(QLatin1String("configure")));
	addPage(page);

	widget = new QWidget(this);
	gridLayout = new QGridLayout(widget);

	label = new QLabel(i18nc("@label:textbox", "Log messages:"), widget);
	gridLayout->addWidget(label, 0, 0);

	QPushButton *pushButton = new QPushButton(i18nc("@action:button", "Show dmesg"));
	pushButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
	connect(pushButton, SIGNAL(clicked()), this, SLOT(showDmesg()));
	gridLayout->addWidget(pushButton, 0, 1);

	QPlainTextEdit *textEdit = new QPlainTextEdit(widget);
	textEdit->setPlainText(Log::getLog());
	textEdit->setReadOnly(true);
	gridLayout->addWidget(textEdit, 1, 0, 1, 2);
	gridLayout->setRowStretch(2, 1);

	page = new KPageWidgetItem(widget, i18nc("@title:group", "Diagnostics"));
	page->setIcon(KIcon(QLatin1String("page-zoom")));
	addPage(page);
}
Ejemplo n.º 19
0
/**
 * Authenticate using OAuth
 *
 * TODO (Dirk): There's some GUI code slipped in here,
 * that really doesn't feel like it's belonging here.
 */
void FbTalker::doOAuth()
{
    // just in case
    m_loginInProgress = true;

    // TODO (Dirk): 
    // Find out whether this signalBusy is used here appropriately.
    emit signalBusy(true);
    KUrl url("https://www.facebook.com/dialog/oauth");
    url.addQueryItem("client_id", m_appID);
    url.addQueryItem("redirect_uri", "https://www.facebook.com/connect/login_success.html");
    // TODO (Dirk): Check which of these permissions can be optional.
    url.addQueryItem("scope", "photo_upload,user_photos,friends_photos,user_photo_video_tags,friends_photo_video_tags,offline_access");
    url.addQueryItem("response_type", "token");
    kDebug() << "OAuth URL: " << url;
    KToolInvocation::invokeBrowser(url.url());
    emit signalBusy(false);
    KDialog* window         = new KDialog(kapp->activeWindow(), 0);
    window->setModal(true);
    window->setWindowTitle( i18n("Facebook Application Authorization") );
    window->setButtons(KDialog::Ok | KDialog::Cancel);
    QWidget* main           = new QWidget(window, 0);
    QLineEdit* textbox      = new QLineEdit( );
    QPlainTextEdit* infobox = new QPlainTextEdit( i18n(
        "Please follow the instructions in the browser window. "
        "When done, copy the Internet address from your browser into the textbox below and press \"OK\"."
    ) );
    infobox->setReadOnly(true);
    QVBoxLayout* layout = new QVBoxLayout;
    layout->addWidget(infobox);
    layout->addWidget(textbox);
    main->setLayout(layout);
    window->setMainWidget(main);

    if( window->exec()  == QDialog::Accepted )
    {
        // Error code and reason from the Facebook service
        QString errorReason;
        QString errorCode;

        url = KUrl( textbox->text() );
        QString fragment = url.fragment();
        kDebug() << "Split out the fragment from the URL: " << fragment;
        QStringList params = fragment.split('&');
        QList<QString>::iterator i = params.begin();
        while( i != params.end() )
        {
            QStringList keyvalue = (*i).split('=');
            if( keyvalue.size() == 2 )
            {
                if( ! keyvalue[0].compare( "access_token" ) )
                {
                    m_accessToken = keyvalue[1];
                }
                else if( ! keyvalue[0].compare( "expires_in" ) )
                {
                    m_sessionExpires = keyvalue[1].toUInt();
                    if( m_sessionExpires != 0 ) {
#if QT_VERSION >= 0x40700
                        m_sessionExpires += QDateTime::currentMSecsSinceEpoch() / 1000;
#else
                        m_sessionExpires += QDateTime::currentDateTime().toTime_t();
#endif
                    }
                }
                else if( ! keyvalue[0].compare( "error_reason" ) )
                {
                    errorReason = keyvalue[1];
                }
                else if( ! keyvalue[0].compare( "error" ) )
                {
                    errorCode = keyvalue[1];
                }
            }
            ++i;
        }
        if( !m_accessToken.isEmpty() && errorCode.isEmpty() && errorReason.isEmpty() )
        {
            return getLoggedInUser();
        }
    }

    authenticationDone(-1, i18n("Canceled by user."));

    // TODO (Dirk): Correct?
    emit signalBusy(false);
}