pluginclipboardbf.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *   Copyright (C) 2006 by Fco. Javier M. C.                               *
00005  *   fcojavmc@todo-redes.com                                               *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #include <QMenu>
00024 #include <QAction>
00025 #include <QObject>
00026 #include <QMessageBox>
00027 #include <QInputDialog>
00028 #include <QStringList>
00029 #include <QClipboard>
00030 #include <QTextStream>
00031 #include <QTranslator>
00032 #include <QTextCodec>
00033 #include <QLocale>
00034 
00035 #include <stdio.h>
00036 
00037 #include "empresabase.h"
00038 #include "funcaux.h"
00039 #include "pluginclipboardbf.h"
00040 
00041 
00042 
00043 
00045 
00048 int entryPoint(QApplication *) {
00049     _depura("Punto de Entrada del plugin de Clipboard", 0);
00051         QTranslator *traductor = new QTranslator(0);
00052         if (confpr->valor(CONF_TRADUCCION) == "locales") {
00053             traductor->load(QString("pluginclipboardbf_") + QLocale::system().name(),
00054                             confpr->valor(CONF_DIR_TRADUCCION).toAscii().constData());
00055         } else {
00056             QString archivo = "pluginclipboardbf_" + confpr->valor(CONF_TRADUCCION);
00057            traductor->load(archivo, confpr->valor(CONF_DIR_TRADUCCION).toAscii().constData());
00058         } // end if
00059         theApp->installTranslator(traductor);
00060     _depura("END Punto de Entrada del plugin de Clipboard\n", 0);
00061     return 0;
00062 }
00063 
00064 
00066 
00070 int SubForm3_SubForm3_Post(SubForm3 *sub) {
00071     _depura("SubForm3_SubForm3_Post", 0);
00072    myplugclipboard *subformclip = new myplugclipboard(sub);
00073    sub->connect(sub, SIGNAL(pintaMenu(QMenu *)), subformclip, SLOT(s_pintaMenu(QMenu *)));
00074    sub->connect(sub, SIGNAL(trataMenu(QAction *)), subformclip, SLOT(s_trataMenu(QAction *)));
00075     _depura("END SubForm3_SubForm3_Post", 0);
00076    return 0;
00077 }
00078 
00079 
00081 
00084 myplugclipboard::myplugclipboard(SubForm3 *parent) : QObject(parent) {
00085     _depura("myplugclipboard::myplugclipboard", 0);
00086     _depura("myplugclipboard::myplugclipboard", 0);
00087 }
00088 
00089 
00091 
00093 myplugclipboard::~myplugclipboard(){
00094     _depura("myplugclipboard::~myplugclipboard", 0);
00095     _depura("myplugclipboard::~myplugclipboard", 0);
00096 }
00097 
00098 
00100 
00103 void myplugclipboard::s_pintaMenu(QMenu *menu) {
00104     _depura("myplugclipboard::s_pintaMenu", 0);
00105     menu->addSeparator();
00106     menu->addAction(tr("Pegar desde Hoja de Calculo"));
00107     _depura("END myplugclipboard::s_pintaMenu", 0);
00108 }
00109 
00110 
00112 
00115 void myplugclipboard::s_trataMenu(QAction *action) {
00116     _depura("myplugclipboard::s_trataMenu", 0);
00117     if (action->text() == tr("Pegar desde Hoja de Calculo")) {
00118         if (theApp->clipboard()->text().contains("\t")) {
00119             pegaODS();
00120         } else {
00121             pegaSXC();
00122         } // end if
00123     } // end if
00124     _depura("myplugclipboard::s_trataMenu", 0);
00125 }
00126 
00127 
00129 
00131 void myplugclipboard::pegaSXC() {
00132     _depura("myplugclipboard::pegaSXC", 0);
00133         SubForm3 *subform = (SubForm3 *) parent();
00134         QString clipboard = theApp->clipboard()->text();
00135 
00136         QStringList lineas = clipboard.split("\n");
00137 
00139         QStringList campos = lineas.at(0).simplified().split(" ");
00140 
00142         int numcampos = campos.size();
00143         int numchars  = lineas.at(0).size() / numcampos;
00144 
00146         for (int i = 1; i < lineas.size() -1 ; ++i) {
00147                 QString cadena_valores = lineas.at(i);
00148 
00150                 SDBRecord  *linea1;
00151                 linea1 = subform->lineaat(subform->rowCount() - 1);
00153                 subform->nuevoRegistro();
00154 
00156                 for (int j = 0; j < numcampos; ++j) {
00158                         QString valorcampo = cadena_valores.left(numchars).simplified();
00159                         cadena_valores = cadena_valores.right(cadena_valores.size()- numchars);
00160                         linea1->setDBvalue(campos.at(j), valorcampo);
00161                 } // end for
00162         } // end for
00163     _depura("END myplugclipboard::pegaSXC", 0);
00164 }
00165 
00166 
00168 
00170 void myplugclipboard::pegaODS() {
00171     _depura("myplugclipboard::pegaODS", 0);
00172         SubForm3 *subform = (SubForm3 *) parent();
00173         QString clipboard = theApp->clipboard()->text();
00174 
00175         QStringList lineas = clipboard.split("\n");
00176 
00178 //      QStringList campos = lineas.at(0).simplified().split(" ");
00179         QStringList campos = lineas.at(0).split("\t");
00180 
00182         int numcampos = campos.size();
00183 
00185         for (int i = 1; i < lineas.size() -1 ; ++i) {
00186                 QStringList campos_valores = lineas.at(i).split("\t");
00187 
00189                 SDBRecord  *linea1;
00190                 linea1 = subform->lineaat(subform->rowCount() - 1);
00192                 subform->nuevoRegistro();
00193 
00195                 for (int j = 0; j < numcampos; ++j) {
00197                         linea1->setDBvalue(campos.at(j), campos_valores.at(j));
00198                 } // end for
00199         } // end for
00200     _depura("END myplugclipboard::pegaODS", 0);
00201 }
00202 
00203 

Generated on Sat Dec 15 00:01:19 2007 for BulmaGes by  doxygen 1.5.1