ClientKitApi.h #1

  • //
  • guest/
  • james_creasy/
  • ClientKit/
  • ClientKitApi.h
  • View
  • Commits
  • Open Download .zip Download (4 KB)
//
// ClientKitApi.h
//

#ifndef ClientKitApi_h
#define ClientKitApi_h

#include <QObject>
#include <QVariant>
#include <QStringList>
#include <QMap>

#include "KCommon.h"

class MainWindow;
class QString;

class Connection
{
public:
	QString port;
	QString user;
	QString client;
	QString charset;

	bool isEmpty() {return port.isEmpty() || user.isEmpty();}
	void clear() {port = QString(); user = QString(); client = QString(); charset = QString();}
};


class ClientKitApi : public QObject
{   
	 Q_OBJECT

public:
	ClientKitApi (QObject* /*parent*/, MainWindow* mainWindow, QString myJSPointerName);
	virtual ~ClientKitApi() {}

// These define the API as seen by the JS
	Q_INVOKABLE QString		getPort()		{return mConnection.port;}   // Should decide if is this is supposed to read from the clientapi or just the cached values
	Q_INVOKABLE QString		getUser()		{return mConnection.user;}   // Because we always set this right before we run a command, the cached values are accurate
	Q_INVOKABLE QString		getClient()		{return mConnection.client;} // Could be changed to be more like other derived APIs
	Q_INVOKABLE QString		getCharset()	{return mConnection.charset;} 
 	Q_INVOKABLE void		setPort(const QString& p)	{updateConnection(p, "", "");}	// move the update logic into the connection class
	Q_INVOKABLE void		setUser(const QString& u)	{updateConnection("", u, "");}
	Q_INVOKABLE void		setClient(const QString& c)	{updateConnection("", "", c);}
	Q_INVOKABLE void		setCharset(const QString& cs)	{mConnection.charset = cs;}
	Q_INVOKABLE void		setInput(const QString& inputForm) {mInputForm = inputForm;}
	Q_INVOKABLE QVariant	run(const QString& command);					// Run a command on a Perforce server from JavaScript
    Q_INVOKABLE QVariant	run(const QVariantList& cmdTokens);
    Q_INVOKABLE QVariant    run(const QString& command, const QVariantList& args);
	// perhaps (command, args, form, callback)
	//     and (command, args, callback)

	Q_INVOKABLE QString		createP4(const QString& p4PointerName);			// Create a new P4 object in the JavaScript

// file/dir i/o api
	Q_INVOKABLE QVariant	readFile(const QString& fname);
	Q_INVOKABLE bool		createFile(const QString& filename, const QString& fileContents);
    Q_INVOKABLE QString		getConfig();
    Q_INVOKABLE QVariant	currentDir();
    Q_INVOKABLE QVariant	applicationPath();
	Q_INVOKABLE QVariant	ls(const QString& dirname);
    Q_INVOKABLE QVariant	ls(const QString& dirname, bool fileInfo);
	Q_INVOKABLE QString		startProcess(const QString& program, const QStringList& arguments);

// container specific api, query and control the frame of the container
	Q_INVOKABLE QVariant	getWindowSize();
	Q_INVOKABLE	void		setWindowSize(const int& x, const int& y);
	Q_INVOKABLE	void		setWindowStyle(const QString& styleName);
	Q_INVOKABLE	QString		getWindowStyle();
	Q_INVOKABLE	QStringList		getWindowStyles();
	Q_INVOKABLE void		setWindowTitle(const QString & windowTitle);

// misc
    Q_INVOKABLE bool		openUrlInBrowser(QString str);	// This is useful for opening, e.g., a help page (opens in system default browser)
	Q_INVOKABLE QVariant	getSystemLocale();
    Q_INVOKABLE QString		getApiVersion()         {   return ".1";  }	// pre-alpha

// not part of ClientKitApi exposed to JavaScript
	Connection	connection() {return mConnection;}
	void		setConnection(Connection con) {mConnection = con;}
	QString		inputData();
	QStringList* errorList() {return &mErrorList;}

private:
	MainWindow*		mMainWindow;
	Connection		mConnection;		// port, user, client
	QStringList		mP4PointersList;
	QString			mInputForm;			// used for commands with -i
	QStringList		mErrorList;			// todo: Should change to a QVariantList?
	QString			mMyJSPointerName;

	bool updateConnection(QString p, QString u, QString c);	// returns true if any changes made
};

#endif // ClientKitApi_h
# Change User Description Committed
#1 8060 james_creasy Client Kit for Perforce