Skip to content

Commit

Permalink
ADDED: tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 17, 2011
1 parent d5ef16b commit f828c8c
Show file tree
Hide file tree
Showing 17 changed files with 693 additions and 104 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[ ] Tabs (tags)
[ ] Lex and parse command line arguments
[ ] Dialog with table "on matched clipboard text do action": REGEX ACTION (same as command line options)
26 changes: 20 additions & 6 deletions src/clipboardbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include "configurationmanager.h"
#include "client_server.h"

ClipboardBrowser::ClipboardBrowser(QWidget *parent) : QListView(parent),
m_update(false), m_to_preload(0), m_menu(NULL)
ClipboardBrowser::ClipboardBrowser(const QString &id, QWidget *parent) :
QListView(parent), m_id(id), m_update(false), m_to_preload(0), m_menu(NULL)
{
setLayoutMode(QListView::Batched);
setBatchSize(10);
Expand Down Expand Up @@ -112,10 +112,10 @@ void ClipboardBrowser::contextMenuAction(QAction *act)
openEditor();
break;
case ActionAct:
emit requestActionDialog(-1);
emit requestActionDialog(this, -1);
break;
case ActionCustom:
emit requestActionDialog(-1, &commands[act->text()]);
emit requestActionDialog(this, -1, &commands[act->text()]);
break;
}
}
Expand All @@ -134,6 +134,7 @@ void ClipboardBrowser::createContextMenu()
font.setBold(true);
act->setFont(font);
act->setData( QVariant(ActionToClipboard) );
act->setShortcut( QKeySequence("Ctrl+C") );

act = m_menu->addAction( QIcon(":/images/remove.png"), tr("&Remove") );
act->setShortcut( QString("Delete") );
Expand Down Expand Up @@ -375,6 +376,11 @@ void ClipboardBrowser::setCurrent(int row, bool cycle, bool selection)
scrollTo(ind); // ensure visible
}

ClipboardItem *ClipboardBrowser::at(int row) const
{
return m->at(row);
}

void ClipboardBrowser::remove()
{
QItemSelectionModel *sel = selectionModel();
Expand Down Expand Up @@ -455,6 +461,14 @@ bool ClipboardBrowser::add(QMimeData *data, bool ignore_empty)
return true;
}

bool ClipboardBrowser::add(ClipboardItem *item)
{
if ( !m->insertRow(0) )
return false;
m->at(0)->setData( cloneData(*item->data()) );
return true;
}

void ClipboardBrowser::loadSettings()
{
ConfigurationManager *cm = ConfigurationManager::instance();
Expand Down Expand Up @@ -492,7 +506,7 @@ void ClipboardBrowser::loadItems()
// restore items
m->clear();

ConfigurationManager::instance()->loadItems(*m);
ConfigurationManager::instance()->loadItems(*m, m_id);
setCurrentIndex( QModelIndex() );

// preload all items
Expand All @@ -508,7 +522,7 @@ void ClipboardBrowser::saveItems(int msec)
return;
}

ConfigurationManager::instance()->saveItems(*m);
ConfigurationManager::instance()->saveItems(*m, m_id);
}

void ClipboardBrowser::timerEvent(QTimerEvent *event)
Expand Down
7 changes: 5 additions & 2 deletions src/clipboardbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ class ClipboardBrowser : public QListView
ActionCustom
};

ClipboardBrowser(QWidget *parent = 0);
ClipboardBrowser(const QString &id, QWidget *parent = 0);
~ClipboardBrowser();
void loadSettings();
bool add(const QString &txt, bool ignore_empty = true);
bool add(QMimeData *item, bool ignore_empty = true);
bool add(ClipboardItem *item);
void remove();
int length() const { return model()->rowCount(); }
QString itemText(int i = -1) const;
Expand All @@ -60,6 +61,7 @@ class ClipboardBrowser : public QListView
return model()->index(i,0);
}
void setCurrent(int row, bool cycle = false, bool selection = false);
ClipboardItem *at(int row) const;

// if items selected: return concatenation of selected items
// else: return text of first item
Expand All @@ -74,6 +76,7 @@ class ClipboardBrowser : public QListView
QMenu *contextMenu() const {return m_menu;}

private:
QString m_id;
int m_maxitems;
QString m_callback;
QStringList m_callback_args;
Expand Down Expand Up @@ -101,7 +104,7 @@ class ClipboardBrowser : public QListView

signals:
void requestSearch(const QString &txt);
void requestActionDialog(int row, const ConfigurationManager::Command *cmd = NULL);
void requestActionDialog(ClipboardBrowser *c, int row, const ConfigurationManager::Command *cmd = NULL);
void requestShow();
void hideSearch();
void escapePressed();
Expand Down
4 changes: 2 additions & 2 deletions src/clipboarddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ClipboardDialog::on_listWidgetFormats_currentItemChanged(
}

ui->labelProperties->setText(
"<b> mime: </b>" + Qt::escape(mime) +
"<b> size: </b>" + QString::number(bytes.size()) + " bytes"
"<strong> mime: </strong>" + Qt::escape(mime) +
"<strong> size: </strong>" + QString::number(bytes.size()) + " bytes"
);
}
12 changes: 6 additions & 6 deletions src/clipboardserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ClipboardServer::ClipboardServer(int &argc, char **argv) :
connect( m_monitorserver, SIGNAL(newConnection()),
this, SLOT(newMonitorConnection()) );

connect( m_wnd->browser(), SIGNAL(changeClipboard(const ClipboardItem*)),
connect( m_wnd, SIGNAL(changeClipboard(const ClipboardItem*)),
this, SLOT(changeClipboard(const ClipboardItem*)));

// run clipboard monitor
Expand Down Expand Up @@ -122,7 +122,7 @@ void ClipboardServer::stopMonitoring()
m_monitor->deleteLater();
m_monitor = NULL;
}
m_wnd->browser()->setAutoUpdate(false);
m_wnd->browser(0)->setAutoUpdate(false);
}

void ClipboardServer::startMonitoring()
Expand All @@ -143,7 +143,7 @@ void ClipboardServer::startMonitoring()
return;
}
}
m_wnd->browser()->setAutoUpdate(true);
m_wnd->browser(0)->setAutoUpdate(true);
}

void ClipboardServer::newConnection()
Expand Down Expand Up @@ -211,7 +211,7 @@ void ClipboardServer::readyRead()
in2 >> item;

QMimeData *data = item.data();
ClipboardBrowser *c = m_wnd->browser();
ClipboardBrowser *c = m_wnd->browser(0);

c->setAutoUpdate(false);
c->add( cloneData(*data) );
Expand All @@ -238,7 +238,7 @@ bool ClipboardServer::doCommand(Arguments &args, QByteArray &response)
if ( args.error() )
return false;

ClipboardBrowser *c = m_wnd->browser();
ClipboardBrowser *c = m_wnd->browser(0);
bool noupdate = false;
QString mime;
QMimeData *data;
Expand Down Expand Up @@ -296,7 +296,7 @@ bool ClipboardServer::doCommand(Arguments &args, QByteArray &response)
command.input = true;
command.sep = sep;
command.wait = false;
m_wnd->action(-1, &command);
m_wnd->action(c, -1, &command);
}
}

Expand Down
37 changes: 28 additions & 9 deletions src/configurationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ConfigurationManager* ConfigurationManager::m_Instance = 0;

ConfigurationManager::ConfigurationManager(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigurationManager)
ui(new Ui::ConfigurationManager),
m_tabs( QStringList() )
{
ui->setupUi(this);
ui->tableCommands->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
Expand All @@ -31,9 +32,9 @@ ConfigurationManager::ConfigurationManager(QWidget *parent) :
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
// ini -> dat

m_datfilename = settings.fileName();
m_datfilename.replace( QRegExp("ini$"), QString("dat") );
m_datfilename.replace( QRegExp(".ini$"), QString("_tab_") );

// read style sheet from configuration
cssFormat = QSettings::registerFormat(
Expand Down Expand Up @@ -65,6 +66,7 @@ QString ConfigurationManager::optionToName(int opt) const
case CopyClipboard: return QString("copy_clipboard");
case CopySelection: return QString("copy_selection");
case ConfirmExit: return QString("confirm_exit");
case Tabs: return QString("tabs");
default: return QString();
}
}
Expand All @@ -84,6 +86,7 @@ ConfigurationManager::nameToOption(const QString &name) const
if (name == "copy_clipboard") return CopyClipboard;
if (name == "copy_selection") return CopySelection;
if (name == "confirm_exit") return ConfirmExit;
if (name == "tabs") return Tabs;
return OptionInvalid;
}

Expand All @@ -102,27 +105,38 @@ QVariant ConfigurationManager::value(int opt) const
case CopyClipboard: return ui->checkBoxCopyClip->isChecked();
case CopySelection: return ui->checkBoxCopySel->isChecked();
case ConfirmExit: return ui->checkBoxConfirmExit->isChecked();
case Tabs: return m_tabs;
default: return QVariant();
}
}

void ConfigurationManager::loadItems(ClipboardModel &model)
void ConfigurationManager::loadItems(ClipboardModel &model, const QString &id)
{
QFile file(m_datfilename);
QString part( id.toLocal8Bit().toBase64() );
part.replace( QChar('/'), QString('-') );
QFile file( m_datfilename + part + QString(".dat") );
file.open(QIODevice::ReadOnly);
QDataStream in(&file);

in >> model;
}

void ConfigurationManager::saveItems(const ClipboardModel &model)
void ConfigurationManager::saveItems(const ClipboardModel &model, const QString &id)
{
QFile file(m_datfilename);
QString part( id.toLocal8Bit().toBase64() );
part.replace( QChar('/'), QString('-') );
QFile file( m_datfilename + part + QString(".dat") );
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << model;
}

void ConfigurationManager::removeItems(const QString &id)
{
QString part( id.toLocal8Bit().toBase64() );
part.replace( QChar('/'), QString('-') );
QFile::remove( m_datfilename + part + QString(".dat") );
}

void ConfigurationManager::readStyleSheet()
{
QSettings cssSettings( cssFormat, QSettings::UserScope,
Expand Down Expand Up @@ -200,6 +214,9 @@ void ConfigurationManager::setValue(int opt, const QVariant &value)
case ConfirmExit:
ui->checkBoxConfirmExit->setChecked( value.toBool() );
break;
case Tabs:
m_tabs = value;
break;
}
}

Expand Down Expand Up @@ -312,7 +329,9 @@ void ConfigurationManager::saveSettings()

settings.beginGroup("Options");
for( int opt=1; opt != OptionsCount; ++opt ) {
settings.setValue(optionToName(opt), value(opt));
QString optname = optionToName(opt);
if ( !optname.isEmpty() )
settings.setValue( optname, value(opt) );
}
settings.endGroup();

Expand Down
7 changes: 5 additions & 2 deletions src/configurationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ConfigurationManager : public QDialog
CopyClipboard,
CopySelection,
ConfirmExit,
Tabs,
OptionsCount
} Option;

Expand Down Expand Up @@ -87,8 +88,9 @@ class ConfigurationManager : public QDialog
QVariant value(int opt) const;
void setValue(int opt, const QVariant &value);

void loadItems(ClipboardModel &model);
void saveItems(const ClipboardModel &model);
void loadItems(ClipboardModel &model, const QString &id);
void saveItems(const ClipboardModel &model, const QString &id);
void removeItems(const QString &id);

QByteArray windowGeometry( const QString &widget_name = QString(),
const QByteArray &geometry = QByteArray() );
Expand All @@ -108,6 +110,7 @@ class ConfigurationManager : public QDialog
private:
static ConfigurationManager *m_Instance;
Ui::ConfigurationManager *ui;
QVariant m_tabs;
QString m_datfilename;
QSettings::Format cssFormat;

Expand Down
2 changes: 2 additions & 0 deletions src/copyq.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<file>images/new.svg</file>
<file>images/logo.svg</file>
<file>images/preferences.svg</file>
<file>images/tab_new.svg</file>
<file>images/tab_remove.svg</file>
</qresource>
</RCC>
Loading

0 comments on commit f828c8c

Please sign in to comment.