Commit 627361e0 authored by Kevin Funk's avatar Kevin Funk
Browse files

util: Reformat source using uncrustify

parent e7021f60
......@@ -41,11 +41,12 @@ namespace {
class ActiveToolTipManager : public QObject
{
Q_OBJECT
public Q_SLOTS:
void doVisibility();
public:
typedef QMultiMap<float, QPair<QPointer<ActiveToolTip>, QString> > ToolTipPriorityMap;
typedef QMultiMap<float, QPair<QPointer<ActiveToolTip>, QString>> ToolTipPriorityMap;
ToolTipPriorityMap registeredToolTips;
};
......@@ -71,7 +72,7 @@ void ActiveToolTipManager::doVisibility()
QRect fullGeometry; //Geometry of all visible tooltips together
for (auto it = registeredToolTips.constBegin(); it != registeredToolTips.constEnd(); ++it) {
QPointer< ActiveToolTip > w = (*it).first;
QPointer<ActiveToolTip> w = (*it).first;
if (w) {
if (exclusive) {
(w.data())->hide();
......@@ -100,19 +101,20 @@ void ActiveToolTipManager::doVisibility()
}
}
}
if (!fullGeometry.isEmpty()) {
QRect oldFullGeometry = fullGeometry;
QRect screenGeometry = QApplication::desktop()->screenGeometry(fullGeometry.topLeft());
if (fullGeometry.bottom() > screenGeometry.bottom()) {
//Move up, avoiding the mouse-cursor
fullGeometry.moveBottom(fullGeometry.top()-10);
fullGeometry.moveBottom(fullGeometry.top() - 10);
if (fullGeometry.adjusted(-20, -20, 20, 20).contains(QCursor::pos())) {
fullGeometry.moveBottom(QCursor::pos().y() - 20);
}
}
if (fullGeometry.right() > screenGeometry.right()) {
//Move to left, avoiding the mouse-cursor
fullGeometry.moveRight(fullGeometry.left()-10);
fullGeometry.moveRight(fullGeometry.left() - 10);
if (fullGeometry.adjusted(-20, -20, 20, 20).contains(QCursor::pos())) {
fullGeometry.moveRight(QCursor::pos().x() - 20);
}
......@@ -139,7 +141,7 @@ void ActiveToolTipManager::doVisibility()
fullGeometry = fullGeometry.united(QRect(QCursor::pos(), QCursor::pos()));
//Set bounding geometry, and remove old tooltips
for (auto it = registeredToolTips.begin(); it != registeredToolTips.end(); ) {
for (auto it = registeredToolTips.begin(); it != registeredToolTips.end();) {
if (!it->first) {
it = registeredToolTips.erase(it);
} else {
......@@ -171,7 +173,7 @@ public:
};
}
ActiveToolTip::ActiveToolTip(QWidget *parent, const QPoint& position)
ActiveToolTip::ActiveToolTip(QWidget* parent, const QPoint& position)
: QWidget(parent, Qt::ToolTip)
, d(new ActiveToolTipPrivate)
{
......@@ -199,7 +201,7 @@ ActiveToolTip::ActiveToolTip(QWidget *parent, const QPoint& position)
ActiveToolTip::~ActiveToolTip() = default;
bool ActiveToolTip::eventFilter(QObject *object, QEvent *e)
bool ActiveToolTip::eventFilter(QObject* object, QEvent* e)
{
switch (e->type()) {
case QEvent::MouseMove:
......@@ -237,7 +239,7 @@ bool ActiveToolTip::eventFilter(QObject *object, QEvent *e)
void ActiveToolTip::addFriendWidget(QWidget* widget)
{
d->friendWidgets_.append((QObject*)widget);
d->friendWidgets_.append(( QObject* )widget);
}
bool ActiveToolTip::insideThis(QObject* object)
......@@ -247,7 +249,7 @@ bool ActiveToolTip::insideThis(QObject* object)
return true;
}
if (object == this || object == (QObject*)this->windowHandle() || d->friendWidgets_.contains(object)) {
if (object == this || object == ( QObject* )this->windowHandle() || d->friendWidgets_.contains(object)) {
return true;
}
object = object->parent();
......@@ -273,8 +275,8 @@ void ActiveToolTip::resizeEvent(QResizeEvent*)
opt.init(this);
QStyleHintReturnMask mask;
if (style()->styleHint( QStyle::SH_ToolTip_Mask, &opt, this, &mask ) && !mask.region.isEmpty()) {
setMask( mask.region );
if (style()->styleHint(QStyle::SH_ToolTip_Mask, &opt, this, &mask) && !mask.region.isEmpty()) {
setMask(mask.region);
}
emit resized();
......@@ -282,8 +284,8 @@ void ActiveToolTip::resizeEvent(QResizeEvent*)
void ActiveToolTip::paintEvent(QPaintEvent* event)
{
QStylePainter painter( this );
painter.setClipRegion( event->region() );
QStylePainter painter(this);
painter.setClipRegion(event->region());
QStyleOptionFrame opt;
opt.init(this);
painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
......@@ -291,7 +293,7 @@ void ActiveToolTip::paintEvent(QPaintEvent* event)
void ActiveToolTip::setHandleRect(const QRect& rect)
{
d->handleRect_= rect;
d->handleRect_ = rect;
}
void ActiveToolTip::adjustRect()
......@@ -326,7 +328,6 @@ void ActiveToolTip::showToolTip(ActiveToolTip* tooltip, float priority, const QS
QMetaObject::invokeMethod(manager(), "doVisibility", Qt::QueuedConnection);
}
void ActiveToolTip::closeEvent(QCloseEvent* event)
{
QWidget::closeEvent(event);
......
......@@ -40,10 +40,11 @@ namespace KDevelop {
class KDEVPLATFORMUTIL_EXPORT ActiveToolTip : public QWidget
{
Q_OBJECT
public:
///@param parent Parent widget. Must not be zero, else the widget won't be shown.
/// @param position Position where to show the tooltip, in global coordinates.
ActiveToolTip(QWidget *parent, const QPoint& position);
ActiveToolTip(QWidget* parent, const QPoint& position);
~ActiveToolTip() override;
///Shows and registers the given tool-tip.
......@@ -57,7 +58,7 @@ public:
///@param uniqueId If this is nonempty, ActiveTooltip will make sure that only one tooltip with the given id is shown at a time
static void showToolTip(ActiveToolTip* tooltip, float priority = 100, const QString& uniqueId = QString());
bool eventFilter(QObject *object, QEvent *e) override;
bool eventFilter(QObject* object, QEvent* e) override;
bool insideThis(QObject* object);
......@@ -84,8 +85,9 @@ Q_SIGNALS:
void mouseIn();
// Emitted whenever mouse-activity is noticed outside of the tooltip area
void mouseOut();
private:
void closeEvent(QCloseEvent* ) override;
void closeEvent(QCloseEvent*) override;
private:
const QScopedPointer<class ActiveToolTipPrivate> d;
......
......@@ -36,10 +36,9 @@ AutoOrientedSplitter::AutoOrientedSplitter(Qt::Orientation orientation, QWidget*
void AutoOrientedSplitter::resizeEvent(QResizeEvent* e)
{
const QSize size = e->size();
const float ratio = (float)size.width() / size.height();
const float ratio = ( float )size.width() / size.height();
const Qt::Orientation orientation = (ratio < 1.0 ? Qt::Vertical : Qt::Horizontal);
setOrientation(orientation);
QSplitter::resizeEvent(e);
}
......@@ -28,14 +28,14 @@
#include <QStringList>
#include <QString>
namespace KDevelop
{
namespace KDevelop {
class CommandExecutorPrivate
{
public:
explicit CommandExecutorPrivate( CommandExecutor* cmd )
: m_exec(cmd), m_useShell(false)
explicit CommandExecutorPrivate(CommandExecutor* cmd)
: m_exec(cmd)
, m_useShell(false)
{
}
CommandExecutor* m_exec;
......@@ -44,67 +44,72 @@ public:
QString m_command;
QStringList m_args;
QString m_workDir;
QMap<QString,QString> m_env;
QMap<QString, QString> m_env;
bool m_useShell;
void procError( QProcess::ProcessError error )
void procError(QProcess::ProcessError error)
{
Q_UNUSED(error)
m_lineMaker->flushBuffers();
emit m_exec->failed( error );
emit m_exec->failed(error);
}
void procFinished( int code, QProcess::ExitStatus status )
void procFinished(int code, QProcess::ExitStatus status)
{
m_lineMaker->flushBuffers();
if( status == QProcess::NormalExit )
if (status == QProcess::NormalExit)
emit m_exec->completed(code);
}
};
CommandExecutor::CommandExecutor( const QString& command, QObject* parent )
: QObject(parent), d(new CommandExecutorPrivate(this))
CommandExecutor::CommandExecutor(const QString& command, QObject* parent)
: QObject(parent)
, d(new CommandExecutorPrivate(this))
{
d->m_process = new KProcess(this);
d->m_process->setOutputChannelMode( KProcess::SeparateChannels );
d->m_lineMaker = new ProcessLineMaker( d->m_process );
d->m_process->setOutputChannelMode(KProcess::SeparateChannels);
d->m_lineMaker = new ProcessLineMaker(d->m_process);
d->m_command = command;
connect( d->m_lineMaker, &ProcessLineMaker::receivedStdoutLines,
this, &CommandExecutor::receivedStandardOutput );
connect( d->m_lineMaker, &ProcessLineMaker::receivedStderrLines,
this, &CommandExecutor::receivedStandardError );
connect( d->m_process, static_cast<void(KProcess::*)(QProcess::ProcessError)>(&KProcess::error),
this, [&] (QProcess::ProcessError error) { d->procError(error); } );
connect( d->m_process, static_cast<void(KProcess::*)(int,QProcess::ExitStatus)>(&KProcess::finished),
this, [&] (int code, QProcess::ExitStatus status) { d->procFinished(code, status); } );
connect(d->m_lineMaker, &ProcessLineMaker::receivedStdoutLines,
this, &CommandExecutor::receivedStandardOutput);
connect(d->m_lineMaker, &ProcessLineMaker::receivedStderrLines,
this, &CommandExecutor::receivedStandardError);
connect(d->m_process, static_cast<void (KProcess::*)(QProcess::ProcessError)>(&KProcess::error),
this, [&](QProcess::ProcessError error) {
d->procError(error);
});
connect(d->m_process, static_cast<void (KProcess::*)(int, QProcess::ExitStatus)>(&KProcess::finished),
this, [&](int code, QProcess::ExitStatus status) {
d->procFinished(code, status);
});
}
CommandExecutor::~CommandExecutor()
{
delete d->m_process;
delete d->m_lineMaker;
}
void CommandExecutor::setEnvironment( const QMap<QString,QString>& env )
void CommandExecutor::setEnvironment(const QMap<QString, QString>& env)
{
d->m_env = env;
}
void CommandExecutor::setEnvironment( const QStringList& env )
void CommandExecutor::setEnvironment(const QStringList& env)
{
QMap<QString,QString> envmap;
QMap<QString, QString> envmap;
for (const QString& var : env) {
int sep = var.indexOf(QLatin1Char('='));
envmap.insert( var.left( sep ), var.mid( sep + 1 ) );
envmap.insert(var.left(sep), var.mid(sep + 1));
}
d->m_env = envmap;
}
void CommandExecutor::setArguments( const QStringList& args )
void CommandExecutor::setArguments(const QStringList& args)
{
d->m_args = args;
}
void CommandExecutor::setWorkingDirectory( const QString& dir )
void CommandExecutor::setWorkingDirectory(const QString& dir)
{
d->m_workDir = dir;
}
......@@ -114,31 +119,33 @@ bool CommandExecutor::useShell() const
return d->m_useShell;
}
void CommandExecutor::setUseShell( bool shell )
void CommandExecutor::setUseShell(bool shell)
{
d->m_useShell = shell;
}
void CommandExecutor::start()
{
for(auto it = d->m_env.constBegin(), itEnd = d->m_env.constEnd(); it!=itEnd; ++it)
{
d->m_process->setEnv( it.key(), it.value() );
for (auto it = d->m_env.constBegin(), itEnd = d->m_env.constEnd(); it != itEnd; ++it) {
d->m_process->setEnv(it.key(), it.value());
}
d->m_process->setWorkingDirectory( d->m_workDir );
if( !d->m_useShell ) {
d->m_process->setProgram( d->m_command, d->m_args );
d->m_process->setWorkingDirectory(d->m_workDir);
if (!d->m_useShell) {
d->m_process->setProgram(d->m_command, d->m_args);
} else {
QStringList arguments;
arguments.reserve(d->m_args.size());
Q_FOREACH( const QString &a, d->m_args ) arguments << KShell::quoteArg( a );
Q_FOREACH (const QString& a, d->m_args)
arguments << KShell::quoteArg(a);
d->m_process->setShellCommand(d->m_command + QLatin1Char(' ') + arguments.join(QLatin1Char(' ')));
}
d->m_process->start();
}
void CommandExecutor::setCommand( const QString& command )
void CommandExecutor::setCommand(const QString& command)
{
d->m_command = command;
}
......
......@@ -24,14 +24,13 @@
#include <QProcess>
#include "utilexport.h"
namespace KDevelop
{
namespace KDevelop {
/**
* Simplifying the exeuction of a Command through (QK)Process.
*
* This class emits only very basic signals when the process writes something
* to stdout or stderr and for signaling completed and failed status of running
* to stdout or stderr and for signaling completed and failed status of running
* the process. This means that a process that is executed without a crash or so
* is considered to be completed, even if it indicates an error during execution
* using a non-zero return value. This needs to be handled by the user of the class
......@@ -50,39 +49,40 @@ namespace KDevelop
class KDEVPLATFORMUTIL_EXPORT CommandExecutor : public QObject
{
Q_OBJECT
public:
/**
* Create a command using the given executable, arguments and environment
*
* The process is not started immediately, instead start() has to be called.
*/
explicit CommandExecutor( const QString& command, QObject* parent = nullptr );
explicit CommandExecutor(const QString& command, QObject* parent = nullptr);
~CommandExecutor() override;
/**
* set additional arguments to be used when executing the command
*/
void setArguments( const QStringList& args );
void setArguments(const QStringList& args);
/**
* set additional environment variables to be used when executing the command
*/
void setEnvironment( const QMap<QString,QString>& env );
void setEnvironment(const QMap<QString, QString>& env);
/**
* set additional environment variables to be used when executing the command
*/
void setEnvironment( const QStringList& env );
void setEnvironment(const QStringList& env);
/**
* Sets the working directory of the command
*/
void setWorkingDirectory( const QString& dir );
void setWorkingDirectory(const QString& dir);
/**
* start the command, after this has been called signals may be emitted
*/
void start();
/**
* kill the process, failed() will likely be emitted
*/
......@@ -91,8 +91,8 @@ public:
/**
* set the Command that should be started, now a commandexecutor can be reused
*/
void setCommand( const QString& command );
void setCommand(const QString& command);
/**
* whether the commands are executed from a shell
*/
......@@ -101,31 +101,31 @@ public:
/**
* if @p shell is true, the command is executed from a shell
*/
void setUseShell( bool shell );
void setUseShell(bool shell);
/**
* @returns the arguments
*/
QStringList arguments() const;
/**
* @returns the command
*/
QString command() const;
/**
* @returns the working directory
*/
QString workingDirectory() const;
Q_SIGNALS:
void receivedStandardError( const QStringList& );
void receivedStandardOutput( const QStringList& );
void receivedStandardError(const QStringList&);
void receivedStandardOutput(const QStringList&);
/**
* Emitted when there was a severe problem executing the process, for example it
* could not be started or crashed during execution.
*/
void failed( QProcess::ProcessError );
void failed(QProcess::ProcessError);
/**
* Emitted when the process was successfully started and finished without crashing
* The @p code parameter indicates the return value from executing the process
......
This diff is collapsed.
......@@ -23,7 +23,7 @@
#include <sys/un.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <netdb.h>
#include <fcntl.h>
#include <cerrno>
#include <assert.h>
......@@ -39,21 +39,21 @@
* The goal of this utility is transforming the abstract unix-socket which is used by dbus
* into a TCP socket which can be forwarded to a target machine by ssh tunneling, and then on
* the target machine back into an abstract unix socket.
*
*
* This tool basically works similar to the "socat" utility, except that it works properly
* for this special case. It is merely responsible for the transformation between abstract unix
* sockets and tcp sockets.
*
*
* Furthermore, this tool makes the 'EXTERNAL' dbus authentication mechanism work even across
* machines with different user IDs.
*
*
* This is how the EXTERNAL mechanism works (I found this in a comment of some ruby dbus library):
* Take the user id (eg integer 1000) make a string out of it "1000", take
* each character and determin hex value "1" => 0x31, "0" => 0x30. You
* obtain for "1000" => 31303030 This is what the server is expecting.
* Why? I dunno. How did I come to that conclusion? by looking at rbus
* code. I have no idea how he found that out.
*
*
* The dbus client performs the EXTERNAL authentication by sending "AUTH EXTERNAL 31303030\r\n" once
* after opening the connection, so we can "repair" the authentication by overwriting the token in that
* string through the correct one.
......@@ -64,15 +64,16 @@ const bool debug = false;
/**
* Returns the valid dbus EXTERNAL authentication token for the current user (see above)
* */
std::string getAuthToken() {
std::string getAuthToken()
{
// Get uid
int uid = getuid();
std::ostringstream uidStream;
uidStream << uid;
std::string uidStr = uidStream.str();
const char hexdigits[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'
......@@ -80,10 +81,10 @@ std::string getAuthToken() {
std::ostringstream hexStream;
for (unsigned int i = 0; i < uidStr.size(); ++i) {
auto byte = (unsigned char)uidStr[i];
auto byte = ( unsigned char )uidStr[i];
hexStream << hexdigits[byte >> 4] << hexdigits[byte & 0x0f];
}
return hexStream.str();
}
......@@ -94,112 +95,101 @@ void shuffleBetweenStreams(int side1, int side2, bool fixSide1AuthToken)
{
char buffer[1000];
char buffer2[1000];
// Set non-blocking mode
int opts = fcntl(side1,F_GETFL);
int opts = fcntl(side1, F_GETFL);
opts |= O_NONBLOCK;
fcntl(side1, F_SETFL, opts);
opts = fcntl(side2,F_GETFL);
opts |= O_NONBLOCK;
opts = fcntl(side2, F_GETFL);
opts |= O_NONBLOCK;
fcntl(side2, F_SETFL, opts);
while(true)
{
while (true) {
int r1 = read(side1, buffer, 500); // We read less than 1000, so we have same additional space when changing the auth token
int r2 = read(side2, buffer2, 500);
if(r1 < -1 || r1 == 0)
{
if(debug)
if (r1 < -1 || r1 == 0) {
if (debug)
std::cerr << "stream 1 failed: " << r1 << std::endl;
return;
}
if(r2 < -1 || r2 == 0)
{
if(debug)
if (r2 < -1 || r2 == 0) {
if (debug)
std::cerr << "stream 2 failed: " << r2 << std::endl;
return;
}
if(r1 > 0)
{
if(debug)
if (r1 > 0) {
if (debug)
std::cerr << "transferring " << r1 << " from 1 to 2" << std::endl;
if(fixSide1AuthToken)
{
if(r1 > 15 && memcmp(buffer, "\0AUTH EXTERNAL ", 15) == 0)
{
if (fixSide1AuthToken) {
if (r1 > 15 && memcmp(buffer, "\0AUTH EXTERNAL ", 15) == 0) {
int endPos = -1;
for(int i = 15; i < r1; ++i)
{
if(buffer[i] == '\r')
{
for (int i = 15; i < r1; ++i) {
if (buffer[i] == '\r') {
endPos = i;
break;
}
}
if(endPos != -1)
{
if (endPos != -1) {
std::string oldToken = std::string(buffer + 15, endPos - 15);
std::string newToken = getAuthToken();
int difference = newToken.size() - oldToken.size();
r1 += difference;
assert(r1 > 0 && r1 <= 1000);
memmove(buffer + endPos + difference, buffer + endPos, r1 - difference - endPos);
memcpy(buffer + 15, newToken.data(), newToken.size());
assert(buffer[endPos + difference] == '\r');
assert(buffer[endPos + difference - 1] == newToken[newToken.size()-1]);
}else{
assert(buffer[endPos + difference - 1] == newToken[newToken.size() - 1]);
} else {
std::cout << "could not fix auth token, not enough data available" << std::endl;
}
}else{
} else {
std::cout << "could not fix auth token" << std::endl;