Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scrap.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /****************************************************************************
00008 ** Form implementation generated from reading ui file 'Bib.ui'
00009 **
00010 ** Created: Sun Oct 14 19:47:56 2001
00011 **
00012 ****************************************************************************/
00013 #include "scrap.h"
00014 #include "scrap.moc"
00015 #include <qfileinfo.h>
00016 #include <qfile.h>
00017 #include <qurl.h>
00018 #include <qtextstream.h>
00019 #include <qdom.h>
00020 #include <qfiledialog.h>
00021 #include <qlayout.h>
00022 #include <qmessagebox.h>
00023 #include <qtoolbutton.h>
00024 #include <qcursor.h>
00025 #include <qtoolbox.h>
00026 #include "query.h"
00027 #include "scpreview.h"
00028 #include "prefsfile.h"
00029 #include "util.h"
00030 #include "commonstrings.h"
00031 #include "prefsmanager.h"
00032 #include "stencilreader.h"
00033 extern QPixmap loadIcon(QString nam);
00034 //CB TODO bring in the prefsManager instance locally here too
00035 
00036 /* The Scrapbook View Class
00037  * inherited from QIconView */
00038 BibView::BibView(QWidget* parent) : QIconView(parent)
00039 {
00040        setAutoArrange(true);
00041        setSorting(true);
00042        setResizeMode(QIconView::Adjust);
00043        objectMap.clear();
00044        ScFilename = "";
00045 }
00046 
00047 void BibView::keyPressEvent(QKeyEvent *k)
00048 {
00049        //Why doesnt this widget send Escape to the QDialog? Lets make Escape work for now anyway.
00050        if (k->key()==Key_Escape && k->state() == 0)
00051        {
00052               QFrame *f=dynamic_cast<QFrame *>(parent());
00053               if (f)
00054               {
00055                      QDialog *d=dynamic_cast<QDialog *>(f->parent());
00056                      if (d)
00057                             d->close();
00058               }
00059        }
00060        else
00061               QIconView::keyPressEvent(k);
00062 }
00063 
00064 QDragObject *BibView::dragObject()
00065 {
00066        QString dt = objectMap[currentItem()->text()].Data;
00067        QFileInfo fi(dt);
00068        if (fi.extension(true).lower() == "sml")
00069        {
00070               QCString cf;
00071               loadRawText(dt, cf);
00072               QString f = QString::fromUtf8(cf.data());
00073               StencilReader *pre = new StencilReader();
00074               dt = pre->createObjects(f);
00075               delete pre;
00076        }
00077        else if (fi.extension(true).lower() == "shape")
00078        {
00079               QCString cf;
00080               loadRawText(dt, cf);
00081               QString f = QString::fromUtf8(cf.data());
00082               StencilReader *pre = new StencilReader();
00083               dt = pre->createShape(f);
00084               delete pre;
00085        }
00086        else if (fi.extension(true).lower() == "sce")
00087        {
00088               if ( fi.exists() )
00089               {
00090                      QUrl ur(dt);
00091                      dt = ur.toString();
00092               }
00093        }
00094        QDragObject *dr = new QTextDrag(dt, this);
00095        dr->setPixmap(objectMap[currentItem()->text()].Preview);
00096        clearSelection();
00097        return dr;
00098 }
00099 
00100 void BibView::AddObj(QString name, QString daten, QPixmap Bild)
00101 {
00102        struct Elem DrElem;
00103        DrElem.Data = daten;
00104        DrElem.Preview = Bild;
00105        objectMap.insert(name, DrElem);
00106 }
00107 
00108 void BibView::checkAndChange(QString &text, QString nam, QString dir)
00109 {
00110        QDomDocument docu("scridoc");
00111        docu.setContent(text);
00112        QDomElement elem = docu.documentElement();
00113        QDomNode DOC = elem.firstChild();
00114        bool hasImage = false;
00115        while(!DOC.isNull())
00116        {
00117               QDomElement pg = DOC.toElement();
00118               if(pg.tagName() == "ITEM")
00119               {
00120                      PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt());
00121                      if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame))
00122                      {
00123                             QString Pfile = pg.attribute("PFILE");
00124                             QString Pfile2 = pg.attribute("PFILE2","");
00125                             QString Pfile3 = pg.attribute("PFILE3","");
00126                             if (!Pfile.isEmpty())
00127                                    hasImage = true;
00128                             if (!Pfile2.isEmpty())
00129                                    hasImage = true;
00130                             if (!Pfile3.isEmpty())
00131                                    hasImage = true;
00132                      }
00133               }
00134               DOC = DOC.nextSibling();
00135        }
00136        QFileInfo fid(nam);
00137        if (hasImage)
00138        {
00139               QDir dd = QDir(dir);
00140               dd.mkdir(QDir::cleanDirPath(QDir::convertSeparators(dir + "/" + fid.baseName())));
00141        }
00142        QString source = "";
00143        QString target = "";
00144        DOC = elem.firstChild();
00145        while(!DOC.isNull())
00146        {
00147               QDomElement pg = DOC.toElement();
00148               if(pg.tagName() == "ITEM")
00149               {
00150                      PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt());
00151                      if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame))
00152                      {
00153                             QString Pfile = pg.attribute("PFILE");
00154                             if (!Pfile.isEmpty())
00155                             {
00156                                    if (static_cast<bool>(pg.attribute("relativePaths", "0").toInt()))
00157                                    {
00158                                           QFileInfo pfi2(QDir::cleanDirPath(QDir::convertSeparators(dir+"/"+Pfile)));
00159                                           source = pfi2.absFilePath();
00160                                    }
00161                                    else
00162                                    {
00163                                           QFileInfo fi(Pfile);
00164                                           source = QDir::cleanDirPath(QDir::convertSeparators(QDir::homeDirPath()+"/"+Pfile));
00165                                    }
00166                                    QFileInfo fi(Pfile);
00167                                    QString target = QDir::cleanDirPath(QDir::convertSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName()));
00168                                    copyFile(source, target);
00169                                    pg.setAttribute("PFILE", fid.baseName() + "/" + fi.fileName());
00170                             }
00171                             QString Pfile2 = pg.attribute("PFILE2","");
00172                             if (!Pfile2.isEmpty())
00173                             {
00174                                    if (static_cast<bool>(pg.attribute("relativePaths", "0").toInt()))
00175                                    {
00176                                           QFileInfo pfi2(QDir::cleanDirPath(QDir::convertSeparators(dir+"/"+Pfile2)));
00177                                           source = pfi2.absFilePath();
00178                                    }
00179                                    else
00180                                    {
00181                                           QFileInfo fi(Pfile2);
00182                                           source = QDir::cleanDirPath(QDir::convertSeparators(QDir::homeDirPath()+"/"+Pfile));
00183                                    }
00184                                    QFileInfo fi(Pfile2);
00185                                    QString target = QDir::cleanDirPath(QDir::convertSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName()));
00186                                    copyFile(source, target);
00187                                    pg.setAttribute("PFILE2", fid.baseName() + "/" + fi.fileName());
00188                             }
00189                             QString Pfile3 = pg.attribute("PFILE3","");
00190                             if (!Pfile3.isEmpty())
00191                             {
00192                                    if (static_cast<bool>(pg.attribute("relativePaths", "0").toInt()))
00193                                    {
00194                                           QFileInfo pfi2(QDir::cleanDirPath(QDir::convertSeparators(dir+"/"+Pfile3)));
00195                                           source = pfi2.absFilePath();
00196                                    }
00197                                    else
00198                                    {
00199                                           QFileInfo fi(Pfile3);
00200                                           source = QDir::cleanDirPath(QDir::convertSeparators(QDir::homeDirPath()+"/"+Pfile3));
00201                                    }
00202                                    QFileInfo fi(Pfile3);
00203                                    QString target = QDir::cleanDirPath(QDir::convertSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName()));
00204                                    copyFile(source, target);
00205                                    pg.setAttribute("PFILE3", fid.baseName() + "/" + fi.fileName());
00206                             }
00207                             pg.setAttribute("relativePaths", 1);
00208                      }
00209               }
00210               DOC = DOC.nextSibling();
00211        }
00212        QFile f(nam);
00213        if(!f.open(IO_WriteOnly))
00214               return ;
00215        QTextStream s;
00216        QCString cs = docu.toCString();
00217        s.setEncoding(QTextStream::UnicodeUTF8);
00218        s.setDevice(&f);
00219        s.writeRawBytes(cs.data(), cs.length());
00220        f.close();
00221 }
00222 
00223 void BibView::SaveContents(QString name, QString oldName)
00224 {
00225        QDir d(oldName, "*.sce", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00226        if ((d.exists()) && (d.count() != 0))
00227        {
00228               for (uint dc = 0; dc < d.count(); ++dc)
00229               {
00230                      QCString cf;
00231                      if (!loadRawText(QDir::cleanDirPath(QDir::convertSeparators(oldName + "/" + d[dc])), cf))
00232                             continue;
00233                      QString ff = QString::fromUtf8(cf.data());
00234                      QPixmap pm;
00235                      QFileInfo fi(QDir::cleanDirPath(QDir::convertSeparators(oldName + "/" + d[dc])));
00236                      QFileInfo fi2(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00237                      if (fi2.exists())
00238                             pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00239                      else
00240                      {
00241                             QString f;
00242                             if (cf.left(16) == "<SCRIBUSELEMUTF8")
00243                                    f = QString::fromUtf8(cf.data());
00244                             else
00245                                    f = cf.data();
00246                             ScPreview *pre = new ScPreview();
00247                             pm = pre->createPreview(f);
00248                             delete pre;
00249                      }
00250                      QFileInfo fi3(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d[dc])));
00251                      pm.save(QDir::cleanDirPath(QDir::convertSeparators(fi3.dirPath()+"/"+fi3.baseName()+".png")), "PNG");
00252                      checkAndChange(ff, QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d[dc])), QDir::cleanDirPath(QDir::convertSeparators(name)));
00253               }
00254        }
00255        QDir d2(oldName, "*.sml", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00256        if ((d2.exists()) && (d2.count() != 0))
00257        {
00258               for (uint dc = 0; dc < d2.count(); ++dc)
00259               {
00260                      QCString cf;
00261                      if (!loadRawText(QDir::cleanDirPath(QDir::convertSeparators(oldName + "/" + d2[dc])), cf))
00262                             continue;
00263                      QFile fil(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d2[dc])));
00264                      if(!fil.open(IO_WriteOnly))
00265                             continue ;
00266                      QTextStream s(&fil);
00267                      s.writeRawBytes(cf.data(), cf.length());
00268                      fil.close();
00269                      QPixmap pm;
00270                      QFileInfo fi(QDir::cleanDirPath(QDir::convertSeparators(oldName + "/" + d2[dc])));
00271                      QFileInfo fi2(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00272                      if (fi2.exists())
00273                             pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00274                      else
00275                      {
00276                             QString f = QString::fromUtf8(cf.data());
00277                             StencilReader *pre = new StencilReader();
00278                             pm = pre->createPreview(f);
00279                             delete pre;
00280                      }
00281                      QFileInfo fi3(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d2[dc])));
00282                      pm.save(QDir::cleanDirPath(QDir::convertSeparators(fi3.dirPath()+"/"+fi3.baseName()+".png")), "PNG");
00283               }
00284        }
00285        QDir d3(name, "*.shape", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00286        if ((d3.exists()) && (d3.count() != 0))
00287        {
00288               for (uint dc = 0; dc < d3.count(); ++dc)
00289               {
00290                      QCString cf;
00291                      if (!loadRawText(QDir::cleanDirPath(QDir::convertSeparators(oldName + "/" + d3[dc])), cf))
00292                             continue;
00293                      QFile fil(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d3[dc])));
00294                      if(!fil.open(IO_WriteOnly))
00295                             continue ;
00296                      QTextStream s(&fil);
00297                      s.writeRawBytes(cf.data(), cf.length());
00298                      fil.close();
00299                      QPixmap pm;
00300                      QFileInfo fi(QDir::cleanDirPath(QDir::convertSeparators(oldName + "/" + d3[dc])));
00301                      QFileInfo fi2(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00302                      if (fi2.exists())
00303                             pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00304                      else
00305                      {
00306                             QString f = QString::fromUtf8(cf.data());
00307                             StencilReader *pre = new StencilReader();
00308                             QString f2 = pre->createShape(f);
00309                             ScPreview *pre2 = new ScPreview();
00310                             pm = pre2->createPreview(f2);
00311                             delete pre;
00312                             delete pre2;
00313                      }
00314                      QFileInfo fi3(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d3[dc])));
00315                      pm.save(QDir::cleanDirPath(QDir::convertSeparators(fi3.dirPath()+"/"+fi3.baseName()+".png")), "PNG");
00316               }
00317        }
00318 }
00319 
00320 void BibView::ReadOldContents(QString name, QString newName)
00321 {
00322        bool isUtf8 = false;
00323        QDomDocument docu("scridoc");
00324        QString ff;
00325        QCString cf;
00326        if (!loadRawText(name, cf))
00327               return;
00328        // these were corrupting the scrapbook entries, removed and works ok now, Riku
00329 //     if (f.startsWith("<SCRIBUSSCRAPUTF8"))
00330 //            ff = QString::fromUtf8(f);
00331 //     else
00332 //            ff = f;
00333        if( cf.left(17) == "<SCRIBUSSCRAPUTF8")
00334        {
00335               ff = QString::fromUtf8(cf.data());
00336               isUtf8 = true;
00337        }
00338        else
00339               ff = QString::fromLocal8Bit(cf.data());
00340        if(!docu.setContent(ff))
00341               return;
00342        QDomElement elem=docu.documentElement();
00343        if ((elem.tagName() != "SCRIBUSSCRAP") && (elem.tagName() != "SCRIBUSSCRAPUTF8"))
00344               return;
00345        QDomNode DOC=elem.firstChild();
00346        while(!DOC.isNull())
00347        {
00348               QDomElement dc=DOC.toElement();
00349               if (dc.tagName()=="OBJEKT")
00350               {
00351                      QFile fi(QDir::cleanDirPath(QDir::convertSeparators(newName + "/" + GetAttr(&dc, "NAME") + ".sce")));
00352                      if(!fi.open(IO_WriteOnly))
00353                             continue ;
00354                      QTextStream s(&fi);
00355                      QString fn = GetAttr(&dc, "DATA");
00356                      cf = isUtf8? fn.utf8() : fn.local8Bit();
00357                      s.writeRawBytes(cf.data(), cf.length());
00358                      fi.close();
00359               }
00360               DOC=DOC.nextSibling();
00361        }
00362 }
00363 
00364 void BibView::ReadContents(QString name)
00365 {
00366        clear();
00367        objectMap.clear();
00368        QString nd;
00369        if (name.endsWith(QDir::convertSeparators("/")))
00370               nd = name.left(name.length()-1);
00371 //     QFileInfo fd(nd);
00372 //     canWrite = fd.permission( QFileInfo::WriteUser );
00373 // Above code is commented out because QFileInfo::permissons does not work properly
00374        QDir d(name, "*.sce", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00375        if ((d.exists()) && (d.count() != 0))
00376        {
00377               for (uint dc = 0; dc < d.count(); ++dc)
00378               {
00379                      QPixmap pm;
00380                      QCString cf;
00381                      if (!loadRawText(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d[dc])), cf))
00382                             continue;
00383                      QFileInfo fi(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d[dc])));
00384                      QFileInfo fi2(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00385                      if (fi2.exists())
00386                             pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00387                      else
00388                      {
00389                             QString f;
00390                             if (cf.left(16) == "<SCRIBUSELEMUTF8")
00391                                    f = QString::fromUtf8(cf.data());
00392                             else
00393                                    f = cf.data();
00394                             ScPreview *pre = new ScPreview();
00395                             pm = pre->createPreview(f);
00396 //                          if (canWrite)
00397 // Above code is commented out because QFileInfo::permissons does not work properly
00398                                    pm.save(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")), "PNG");
00399                             delete pre;
00400                      }
00401                      AddObj(fi.baseName(), QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d[dc])), pm);
00402               }
00403        }
00404        QDir d2(name, "*.sml", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00405        if ((d2.exists()) && (d2.count() != 0))
00406        {
00407               for (uint dc = 0; dc < d2.count(); ++dc)
00408               {
00409                      QPixmap pm;
00410                      QCString cf;
00411                      if (!loadRawText(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d2[dc])), cf))
00412                             continue;
00413                      QFileInfo fi(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d2[dc])));
00414                      QFileInfo fi2(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00415                      if (fi2.exists())
00416                             pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00417                      else
00418                      {
00419                             QString f = QString::fromUtf8(cf.data());
00420                             StencilReader *pre = new StencilReader();
00421                             pm = pre->createPreview(f);
00422 //                          if (canWrite)
00423 // Above code is commented out because QFileInfo::permissons does not work properly
00424                                    pm.save(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")), "PNG");
00425                             delete pre;
00426                      }
00427                      AddObj(fi.baseName(), QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d2[dc])), pm);
00428               }
00429        }
00430        QDir d3(name, "*.shape", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00431        if ((d3.exists()) && (d3.count() != 0))
00432        {
00433               for (uint dc = 0; dc < d3.count(); ++dc)
00434               {
00435                      QPixmap pm;
00436                      QCString cf;
00437                      if (!loadRawText(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d3[dc])), cf))
00438                             continue;
00439                      QFileInfo fi(QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d3[dc])));
00440                      QFileInfo fi2(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00441                      QFileInfo fi2p(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".xpm")));
00442                      if ((fi2.exists()) || (fi2p.exists()))
00443                      {
00444                             if (fi2.exists())
00445                                    pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".png")));
00446                             else
00447                                    pm.load(QDir::cleanDirPath(QDir::convertSeparators(fi.dirPath()+"/"+fi.baseName()+".xpm")));
00448                      }
00449                      else
00450                      {
00451                             QString f = QString::fromUtf8(cf.data());
00452                             StencilReader *pre = new StencilReader();
00453                             QString f2 = pre->createShape(f);
00454                             ScPreview *pre2 = new ScPreview();
00455                             pm = pre2->createPreview(f2);
00456                             delete pre;
00457                             delete pre2;
00458                      }
00459                      AddObj(fi.baseName(), QDir::cleanDirPath(QDir::convertSeparators(name + "/" + d3[dc])), pm);
00460               }
00461        }
00462        QMap<QString,Elem>::Iterator itf;
00463        for (itf = objectMap.begin(); itf != objectMap.end(); ++itf)
00464        {
00465               (void) new QIconViewItem(this, itf.key(), itf.data().Preview);
00466        }
00467 }
00468 
00469 /* This is the main Dialog-Class for the Scrapbook */
00470 Biblio::Biblio( QWidget* parent) : ScrPaletteBase( parent, "Sclib", false, 0 )
00471 {
00472        resize( 230, 190 );
00473        BiblioLayout = new QVBoxLayout( this );
00474        BiblioLayout->setSpacing( 0 );
00475        BiblioLayout->setMargin( 0 );
00476 
00477        buttonLayout = new QHBoxLayout;
00478        buttonLayout->setSpacing( 5 );
00479        buttonLayout->setMargin( 0 );
00480        newButton = new QToolButton(this, "newButton" );
00481        newButton->setPixmap(loadIcon("16/document-new.png"));
00482        loadButton = new QToolButton(this, "loadButton" );
00483        loadButton->setPixmap(loadIcon("16/document-open.png"));
00484        saveAsButton = new QToolButton(this, "saveAsButton" );
00485        saveAsButton->setPixmap(loadIcon("16/document-save-as.png"));
00486        importButton = new QToolButton(this, "importButton" );
00487        importButton->setPixmap(loadIcon("compfile16.png"));
00488        closeButton = new QToolButton(this, "closeButton" );
00489        closeButton->setPixmap(loadIcon("16/close.png"));
00490        buttonLayout->addWidget( newButton );
00491        buttonLayout->addWidget( loadButton );
00492        buttonLayout->addWidget( saveAsButton );
00493        buttonLayout->addWidget( importButton );
00494        buttonLayout->addWidget( closeButton );
00495        QSpacerItem* spacer = new QSpacerItem( 16, 16, QSizePolicy::Expanding, QSizePolicy::Minimum );
00496        buttonLayout->addItem( spacer );
00497        BiblioLayout->addLayout( buttonLayout );
00498 
00499 
00500 //     Frame3 = new QTabWidget( this, "Frame3" );
00501        Frame3 = new QToolBox( this, "Frame3" );
00502        activeBView = new BibView(this);
00503 //     Frame3->addTab(activeBView, tr("Main"));
00504        Frame3->addItem(activeBView, tr("Main"));
00505        tempBView = new BibView(this);
00506 //     Frame3->addTab(tempBView, tr("Copied Items"));
00507        Frame3->addItem(tempBView, tr("Copied Items"));
00508        tempCount = 0;
00509        BiblioLayout->addWidget( Frame3 );
00510 
00511        languageChange();
00512 
00513        connect(newButton, SIGNAL(clicked()), this, SLOT(NewLib()));
00514        connect(loadButton, SIGNAL(clicked()), this, SLOT(Load()));
00515        connect(saveAsButton, SIGNAL(clicked()), this, SLOT(SaveAs()));
00516        connect(importButton, SIGNAL(clicked()), this, SLOT(Import()));
00517        connect(closeButton, SIGNAL(clicked()), this, SLOT(closeLib()));
00518        connect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00519        connect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00520        connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00521 //     connect(Frame3, SIGNAL(currentChanged(QWidget*)), this, SLOT(libChanged(QWidget* )));
00522        connect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int )));
00523 }
00524 
00525 void Biblio::setOpenScrapbooks(QStringList &fileNames)
00526 {
00527        disconnect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00528        disconnect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00529        disconnect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00530        for (uint rd = 0; rd < fileNames.count(); ++rd)
00531        {
00532               QString fileName = fileNames[rd];
00533               if (!fileName.isEmpty())
00534               {
00535                      QDir d(fileName);
00536                      activeBView = new BibView(this);
00537 /*                   if (!activeBView->canWrite)
00538                             Frame3->addTab(activeBView, loadIcon("spot.png"), d.dirName());
00539                      else */
00540 // Above code is commented out because QFileInfo::permissons does not work properly
00541 //                   Frame3->addTab(activeBView, d.dirName());
00542                      Frame3->addItem(activeBView, d.dirName());
00543                      activeBView->ReadContents(fileName);
00544                      activeBView->ScFilename = fileName;
00545               }
00546        }
00547 //     activeBView = (BibView*)Frame3->page(0);
00548 //     Frame3->setCurrentPage(0);
00549        activeBView = (BibView*)Frame3->item(0);
00550        Frame3->setCurrentIndex(0);
00551        connect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00552        connect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00553        connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00554 }
00555 
00556 QStringList Biblio::getOpenScrapbooks()
00557 {
00558        QStringList ret;
00559        ret.clear();
00560        if (Frame3->count() > 2) // omit the first 2 Tabs since they contain the main and temp scrapbook
00561        {
00562               for (int a = 2; a < Frame3->count(); a++)
00563               {
00564 //                   BibView* bv = (BibView*)Frame3->page(a);
00565                      BibView* bv = (BibView*)Frame3->item(a);
00566                      ret.append(bv->ScFilename);
00567               }
00568        }
00569        return ret;
00570 }
00571 
00572 void Biblio::setScrapbookFileName(QString fileName)
00573 {
00574        activeBView->ScFilename=fileName;
00575 }
00576 
00577 const QString Biblio::getScrapbookFileName()
00578 {
00579        return activeBView->ScFilename;
00580 }
00581 
00582 const int Biblio::objectCount()
00583 {
00584        return activeBView->objectMap.count();
00585 }
00586 
00587 void Biblio::readOldContents(QString fileName, QString newName)
00588 {
00589        activeBView->ReadOldContents(fileName, newName);
00590 }
00591 
00592 void Biblio::readContents(QString fileName)
00593 {
00594        activeBView->ReadContents(fileName);
00595 }
00596 
00597 void Biblio::readTempContents(QString fileName)
00598 {
00599        tempBView->ReadContents(fileName);
00600        tempBView->ScFilename = fileName;
00601        tempCount = tempBView->objectMap.count();
00602 }
00603 
00604 void Biblio::installEventFilter(const QObject *filterObj)
00605 {
00606        ScrPaletteBase::installEventFilter(filterObj);
00607        activeBView->installEventFilter(filterObj);
00608        tempBView->installEventFilter(filterObj);
00609 }
00610 
00611 void Biblio::NewLib()
00612 {
00613        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00614        QString fileName = QFileDialog::getExistingDirectory("", this, "d", tr("Choose a Scrapbook Directory"), true);
00615        if (!fileName.isEmpty())
00616        {
00617               for (int a = 0; a < Frame3->count(); a++)
00618               {
00619 //                   BibView* bv = (BibView*)Frame3->page(a);
00620                      BibView* bv = (BibView*)Frame3->item(a);
00621                      if (fileName == bv->ScFilename)
00622                             return;
00623               }
00624               disconnect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00625               disconnect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00626               disconnect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00627               QDir d(fileName);
00628               activeBView = new BibView(this);
00629 //            Frame3->addTab(activeBView, d.dirName());
00630               Frame3->addItem(activeBView, d.dirName());
00631               activeBView->ScFilename = fileName;
00632 //            Frame3->showPage(activeBView);
00633               Frame3->setCurrentItem(activeBView);
00634               d.cdUp();
00635               dirs->set("scrap_load", d.absPath());
00636               connect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00637               connect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00638               connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00639        }
00640 }
00641 
00642 void Biblio::Load()
00643 {
00644        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00645        QString fileName = QFileDialog::getExistingDirectory(dirs->get("scrap_load", "."), this, "d", tr("Choose a Scrapbook Directory"), true);
00646        if (!fileName.isEmpty())
00647        {
00648               for (int a = 0; a < Frame3->count(); a++)
00649               {
00650 //                   BibView* bv = (BibView*)Frame3->page(a);
00651                      BibView* bv = (BibView*)Frame3->item(a);
00652                      if (fileName == bv->ScFilename)
00653                             return;
00654               }
00655               disconnect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00656               disconnect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00657               disconnect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00658               QDir d(fileName);
00659               activeBView = new BibView(this);
00660 /*            if (!activeBView->canWrite)
00661                      Frame3->addTab(activeBView, loadIcon("spot.png"), d.dirName());
00662               else */
00663 // Above code is commented out because QFileInfo::permissons does not work properly
00664 //            Frame3->addTab(activeBView, d.dirName());
00665               Frame3->addItem(activeBView, d.dirName());
00666               activeBView->ReadContents(fileName);
00667               activeBView->ScFilename = fileName;
00668 //            Frame3->showPage(activeBView);
00669               Frame3->setCurrentItem(activeBView);
00670               d.cdUp();
00671               dirs->set("scrap_load", d.absPath());
00672               connect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00673               connect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00674               connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00675        }
00676 }
00677 
00678 void Biblio::Import()
00679 {
00680        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00681        QString s = QFileDialog::getOpenFileName(dirs->get("old_scrap_load", "."),
00682                                                 tr("Scrapbook (*.scs)"),
00683                                                 this,
00684                                                 "open file dialog",
00685                                                 tr("Choose a scrapbook file to import"));
00686        
00687        if (!s.isEmpty())
00688        {
00689               dirs->set("old_scrap_load", s.left(s.findRev(QDir::convertSeparators("/"))));
00690               
00691               QString scrapbookFileO = s;
00692               QFileInfo scrapbookFileInfoO = QFileInfo(scrapbookFileO);
00693               if (scrapbookFileInfoO.exists())
00694               {
00695                      readOldContents(scrapbookFileO, activeBView->ScFilename);
00696                      readContents(activeBView->ScFilename);
00697               }
00698        }
00699 }
00700 
00701 void Biblio::SaveAs()
00702 {
00703        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00704        QString fn = QFileDialog::getExistingDirectory(dirs->get("scrap_saveas", "."), this, "d", tr("Choose a Directory"), true);
00705        if (!fn.isEmpty())
00706        {
00707               for (int a = 0; a < Frame3->count(); a++)
00708               {
00709 //                   BibView* bv = (BibView*)Frame3->page(a);
00710                      BibView* bv = (BibView*)Frame3->item(a);
00711                      if (fn == bv->ScFilename)
00712                             return;
00713               }
00714               QDir d(fn);
00715               dirs->set("scrap_saveas", fn);
00716               activeBView->SaveContents(fn, activeBView->ScFilename);
00717 //            activeBView->ScFilename = fn;
00718 //            Frame3->changeTab(activeBView, d.dirName());
00719               d.cdUp();
00720               dirs->set("scrap_saveas", d.absPath());
00721        }
00722 }
00723 
00724 void Biblio::closeLib()
00725 {
00726        if (Frame3->count() == 2)
00727               close();
00728 //     if ((Frame3->currentPageIndex() == 0) || (Frame3->currentPageIndex() == 1))
00729        if ((Frame3->currentIndex() == 0) || (Frame3->currentIndex() == 1))
00730               return;
00731        else
00732        {
00733               disconnect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00734               disconnect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00735               disconnect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00736 //            Frame3->removePage(activeBView);
00737               Frame3->removeItem(activeBView);
00738 //            delete activeBView;   currently disabled as the whole TabWidget vanishes when executing that delete?????
00739 //            activeBView = (BibView*)Frame3->page(0);
00740 //            Frame3->setCurrentPage(0);
00741               activeBView = (BibView*)Frame3->item(0);
00742               Frame3->setCurrentIndex(0);
00743               connect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00744               connect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00745               connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00746        }
00747 }
00748 
00749 // void Biblio::libChanged(QWidget *lib)
00750 void Biblio::libChanged(int index)
00751 {
00752        disconnect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00753        disconnect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00754        disconnect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00755 //     activeBView = (BibView*)lib;
00756        activeBView = (BibView*)Frame3->item(index);
00757        connect(activeBView, SIGNAL(dropped(QDropEvent *, const QValueList<QIconDragItem> &)), this, SLOT(DropOn(QDropEvent *)));
00758        connect(activeBView, SIGNAL(mouseButtonClicked(int, QIconViewItem*, const QPoint &)), this, SLOT(HandleMouse(int, QIconViewItem*)));
00759        connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00760 }
00761 
00762 void Biblio::HandleMouse(int button, QIconViewItem *ite)
00763 {
00764        int mret, del, ren;
00765        if ((ite != 0) && (button == Qt::RightButton))
00766        {
00767               QPopupMenu *pmenu = new QPopupMenu();
00768               QPopupMenu *pmenu2 = new QPopupMenu();
00769               QPopupMenu *pmenu3 = new QPopupMenu();
00770               for (int a = 0; a < Frame3->count(); a++)
00771               {
00772 //                   BibView* bv = (BibView*)Frame3->page(a);
00773                      BibView* bv = (BibView*)Frame3->item(a);
00774                      if (bv != activeBView)
00775                      {
00776 //                          pmenu2->insertItem(Frame3->tabLabel(Frame3->page(a)), a);
00777 //                          pmenu3->insertItem(Frame3->tabLabel(Frame3->page(a)), a);
00778                             pmenu2->insertItem(Frame3->itemLabel(Frame3->indexOf(Frame3->item(a))), a);
00779                             pmenu3->insertItem(Frame3->itemLabel(Frame3->indexOf(Frame3->item(a))), a);
00780                      }
00781               }
00782               connect(pmenu2, SIGNAL(activated(int)), this, SLOT(copyObj(int)));
00783               connect(pmenu3, SIGNAL(activated(int)), this, SLOT(moveObj(int)));
00784               qApp->setOverrideCursor(QCursor(ArrowCursor), true);
00785               ren = pmenu->insertItem( tr("Rename"));
00786               del = pmenu->insertItem( tr("Delete"));
00787               pmenu->insertItem( tr("Copy To:"), pmenu2);
00788               pmenu->insertItem( tr("Move To:"), pmenu3);
00789               mret = pmenu->exec(QCursor::pos());
00790               if (mret == del)
00791                      DeleteObj(ite->text(), ite);
00792               if (mret == ren)
00793               {
00794                      ite->setRenameEnabled(true);
00795                      OldName = ite->text();
00796                      ite->rename();
00797                      ite->setRenameEnabled(false);
00798               }
00799               delete pmenu;
00800        }
00801        activeBView->clearSelection();
00802 }
00803 
00804 bool Biblio::copyObj(int id)
00805 {
00806        QIconViewItem *ite = activeBView->currentItem();
00807        QString nam = ite->text();
00808 //     BibView* bv = (BibView*)Frame3->page(id);
00809        BibView* bv = (BibView*)Frame3->item(id);
00810        if (bv->objectMap.contains(nam))
00811        {
00812               Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
00813               dia->setEditText(nam, true);
00814               if (dia->exec())
00815               {
00816                      nam = dia->getEditText();
00817                      while (activeBView->objectMap.contains(nam))
00818                      {
00819                             if (!dia->exec())
00820                             {
00821                                    delete dia;
00822                                    return false;
00823                             }
00824                             nam = dia->getEditText();
00825                      }
00826               }
00827               else
00828               {
00829                      delete dia;
00830                      return false;
00831               }
00832        }
00833        QPixmap pm;
00834        QCString cf;
00835        if (!loadRawText(QDir::cleanDirPath(activeBView->objectMap[ite->text()].Data), cf))
00836               return false;
00837        pm = activeBView->objectMap[ite->text()].Preview;
00838        QString dt = activeBView->objectMap[ite->text()].Data;
00839        QFileInfo fi(dt);
00840        QFile f(QDir::cleanDirPath(QDir::convertSeparators(bv->ScFilename + "/" + nam + "." + fi.extension(true).lower())));
00841        if(!f.open(IO_WriteOnly))
00842               return false;
00843        QTextStream s;
00844        s.setEncoding(QTextStream::UnicodeUTF8);
00845        s.setDevice(&f);
00846        s.writeRawBytes(cf.data(), cf.length());
00847        f.close();
00848        bv->AddObj(nam, QDir::cleanDirPath(QDir::convertSeparators(bv->ScFilename + "/" + nam + "." + fi.extension(true).lower())), pm);
00849        pm.save(QDir::cleanDirPath(QDir::convertSeparators(bv->ScFilename + "/" + nam +".png")), "PNG");
00850        QFileInfo fiD(QDir::convertSeparators(activeBView->ScFilename + "/" + fi.baseName()));
00851        if ((fiD.exists()) && (fiD.isDir()))
00852        {
00853               QDir dd = QDir(QDir::cleanDirPath(QDir::convertSeparators(bv->ScFilename)));
00854               dd.mkdir(QDir::cleanDirPath(QDir::convertSeparators(bv->ScFilename + "/" + nam)));
00855               QDir d(QDir::convertSeparators(activeBView->ScFilename + "/" + fi.baseName()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00856               if ((d.exists()) && (d.count() != 0))
00857               {
00858                      for (uint dc = 0; dc < d.count(); ++dc)
00859                      {
00860                             QString source = QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + fi.baseName() + "/" + d[dc]));
00861                             QString target = QDir::cleanDirPath(QDir::convertSeparators(bv->ScFilename + "/" + nam + "/" + d[dc]));
00862                             copyFile(source, target);
00863                      }
00864               }
00865               if (fiD.baseName() != nam)
00866                      adjustReferences(QDir::convertSeparators(bv->ScFilename + "/" + nam + "." + fi.extension(true).lower()));
00867        }
00868        (void) new QIconViewItem(bv, nam, pm);
00869        if (bv == tempBView)
00870        {
00871               tempCount++;
00872               if (tempBView->objectMap.count() > static_cast<uint>(PrefsManager::instance()->appPrefs.numScrapbookCopies))
00873               {
00874                      QMap<QString,BibView::Elem>::Iterator it;
00875                      it = tempBView->objectMap.begin();
00876                      QFile f(it.data().Data);
00877                      f.remove();
00878                      QFileInfo fi(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
00879                      if (fi.exists())
00880                      {
00881                             QFile f2(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
00882                             f2.remove();
00883                      }
00884                      QFileInfo fiD(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
00885                      if ((fiD.exists()) && (fiD.isDir()))
00886                      {
00887                             QDir dd = QDir(QDir::convertSeparators(tempBView->ScFilename));
00888                             QDir d(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00889                             if ((d.exists()) && (d.count() != 0))
00890                             {
00891                                    for (uint dc = 0; dc < d.count(); ++dc)
00892                                    {
00893                                           QFile::remove(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + "/" + d[dc]));
00894                                    }
00895                             }
00896                             dd.rmdir(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
00897                      }
00898                      tempBView->objectMap.remove(it);
00899                      QIconViewItem* ite = tempBView->firstItem();
00900                      if (ite != 0)
00901                             delete ite;
00902                      tempBView->sort(activeBView->sortDirection());
00903                      tempBView->arrangeItemsInGrid(true);
00904               }
00905               emit updateRecentMenue();
00906        }
00907        return true;
00908 }
00909 
00910 void Biblio::moveObj(int id)
00911 {
00912        if (copyObj(id))
00913        {
00914               QIconViewItem *ite = activeBView->currentItem();
00915               DeleteObj(ite->text(), ite);
00916        }
00917 }
00918 
00919 void Biblio::DeleteObj(QString name, QIconViewItem *ite)
00920 {
00921 /*     if (!activeBView->canWrite)
00922               return; */
00923 // Above code is commented out because QFileInfo::permissons does not work properly
00924        QFile::remove(activeBView->objectMap[name].Data);
00925        QFileInfo fi(QDir::convertSeparators(activeBView->ScFilename + "/" + name + ".png"));
00926        if (fi.exists())
00927               QFile::remove(QDir::convertSeparators(activeBView->ScFilename + "/" + name + ".png"));
00928        QFileInfo fiD(QDir::convertSeparators(activeBView->ScFilename + "/" + name));
00929        if ((fiD.exists()) && (fiD.isDir()))
00930        {
00931               QDir dd = QDir(QDir::convertSeparators(activeBView->ScFilename));
00932               QDir d(QDir::convertSeparators(activeBView->ScFilename + "/" + name), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
00933               if ((d.exists()) && (d.count() != 0))
00934               {
00935                      for (uint dc = 0; dc < d.count(); ++dc)
00936                      {
00937                             QFile::remove(QDir::convertSeparators(activeBView->ScFilename + "/" + name + "/" + d[dc]));
00938                      }
00939               }
00940               dd.rmdir(name);
00941        }
00942        activeBView->objectMap.remove(name);
00943        delete ite;
00944        activeBView->sort(activeBView->sortDirection());
00945        activeBView->arrangeItemsInGrid(true);
00946        if (activeBView == tempBView)
00947               emit updateRecentMenue();
00948 }
00949 
00950 void Biblio::ItemRenamed(QIconViewItem *ite)
00951 {
00952 /*     if (!activeBView->canWrite)
00953               return; */
00954 // Above code is commented out because QFileInfo::permissons does not work properly
00955        QString ObjData;
00956        QPixmap ObjPreview;
00957        disconnect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00958        if (OldName != ite->text())
00959        {
00960               if (activeBView->objectMap.contains(ite->text()))
00961               {
00962                      QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not unique.\nPlease choose another.").arg(ite->text()), CommonStrings::tr_OK);
00963                      ite->setText(OldName);
00964               }
00965               else
00966               {
00967                      ObjData = activeBView->objectMap[OldName].Data;
00968                      ObjPreview = activeBView->objectMap[OldName].Preview;
00969                      QDir d = QDir();
00970                      d.rename(ObjData, QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + ite->text() + ".sce")));
00971                      QFileInfo fi(QDir::convertSeparators(activeBView->ScFilename + "/" + OldName + ".png"));
00972                      if (fi.exists())
00973                             d.rename(QDir::convertSeparators(activeBView->ScFilename + "/" + OldName + ".png"), QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + ite->text() + ".png")));
00974                      QFileInfo fiD(QDir::convertSeparators(activeBView->ScFilename + "/" + OldName));
00975                      if ((fiD.exists()) && (fiD.isDir()))
00976                      {
00977                             QDir d = QDir();
00978                             d.rename(QDir::convertSeparators(activeBView->ScFilename + "/" + OldName), QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + ite->text())));
00979                             adjustReferences(QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + ite->text() + ".sce")));
00980                      }
00981                      activeBView->objectMap.remove(OldName);
00982                      activeBView->AddObj(ite->text(), QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + ite->text() + ".sce")), ObjPreview);
00983                      activeBView->sort(activeBView->sortDirection());
00984                      activeBView->arrangeItemsInGrid(true);
00985                      if (activeBView == tempBView)
00986                             emit updateRecentMenue();
00987               }
00988        }
00989        connect(activeBView, SIGNAL(itemRenamed(QIconViewItem*)), this, SLOT(ItemRenamed(QIconViewItem*)));
00990 }
00991 
00992 void Biblio::adjustReferences(QString nam)
00993 {
00994        QCString cf;
00995        if (loadRawText(nam, cf))
00996        {
00997               QString f;
00998               if (cf.left(16) == "<SCRIBUSELEMUTF8")
00999                      f = QString::fromUtf8(cf.data());
01000               else
01001               f = cf.data();
01002               QDomDocument docu("scridoc");
01003               docu.setContent(f);
01004               QDomElement elem = docu.documentElement();
01005               QDomNode DOC = elem.firstChild();
01006               QFileInfo fid(nam);
01007               while(!DOC.isNull())
01008               {
01009                      QDomElement pg = DOC.toElement();
01010                      if(pg.tagName() == "ITEM")
01011                      {
01012                             PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt());
01013                             if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame))
01014                             {
01015                                    QString Pfile = pg.attribute("PFILE");
01016                                    if (!Pfile.isEmpty())
01017                                    {
01018                                           QFileInfo fi(Pfile);
01019                                           pg.setAttribute("PFILE", fid.baseName() + "/" + fi.fileName());
01020                                    }
01021                                    QString Pfile2 = pg.attribute("PFILE2","");
01022                                    if (!Pfile2.isEmpty())
01023                                    {
01024                                           QFileInfo fi(Pfile2);
01025                                           pg.setAttribute("PFILE2", fid.baseName() + "/" + fi.fileName());
01026                                    }
01027                                    QString Pfile3 = pg.attribute("PFILE3","");
01028                                    if (!Pfile3.isEmpty())
01029                                    {
01030                                           QFileInfo fi(Pfile3);
01031                                           pg.setAttribute("PFILE3", fid.baseName() + "/" + fi.fileName());
01032                                    }
01033                                    pg.setAttribute("relativePaths", 1);
01034                             }
01035                      }
01036                      DOC = DOC.nextSibling();
01037               }
01038               QFile fl(nam);
01039               if(!fl.open(IO_WriteOnly))
01040                      return ;
01041               QTextStream s;
01042               QCString cs = docu.toCString();
01043               s.setEncoding(QTextStream::UnicodeUTF8);
01044               s.setDevice(&fl);
01045               s.writeRawBytes(cs.data(), cs.length());
01046               fl.close();
01047        }
01048 }
01049 
01050 void Biblio::DropOn(QDropEvent *e)
01051 {
01052        bool img;
01053        QString text, nam, tmp = "";
01054        if (QTextDrag::decode(e, text))
01055        {
01056               QUrl ur(text);
01057               QFileInfo fi = QFileInfo(ur.path());
01058               QString ext = fi.extension(false).lower();
01059               img = ((ext=="eps")||(ext=="epsi")||(ext=="ps")||(ext=="png")||(ext=="gif")||(ext=="jpg")||(ext=="xpm"));
01060               if ((fi.exists()) && (!img))
01061               {
01062                      QCString rawText;
01063                      if (loadRawText(ur.path(), rawText))
01064                      {
01065                             if (rawText.left(16) == "<SCRIBUSELEMUTF8")
01066                                    tmp = QString::fromUtf8(rawText.data());
01067                             else if (rawText.left(13) == "<SCRIBUSELEM>")
01068                                    tmp = rawText;
01069                      }
01070               }
01071               else
01072               {
01073                      if (text.startsWith("<SCRIBUSELEM"))
01074                      {
01075                             tmp = text;
01076                      }
01077               }
01078               text = tmp;
01079               ObjFromMenu(text);
01080        }
01081 }
01082 
01083 void Biblio::ObjFromMenu(QString text)
01084 {
01085        QString nam, tmp;
01086 /*     if (!activeBView->canWrite)
01087               return; */
01088 // Above code is commented out because QFileInfo::permissons does not work properly
01089 //     if (Frame3->currentPageIndex() == 1)
01090        if (Frame3->currentIndex() == 1)
01091        {
01092               nam = tr("Object") + tmp.setNum(tempCount);
01093               tempCount++;
01094        }
01095        else
01096               nam = tr("Object") + tmp.setNum(activeBView->objectMap.count());
01097        Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
01098        dia->setEditText(nam, true);
01099        if (dia->exec())
01100        {
01101               nam = dia->getEditText();
01102               while (activeBView->objectMap.contains(nam))
01103               {
01104                      if (!dia->exec())
01105                      {
01106                             delete dia;
01107                             return;
01108                      }
01109                      nam = dia->getEditText();
01110               }
01111        }
01112        else
01113        {
01114               delete dia;
01115               return;
01116        }
01117        delete dia;
01118        QString ff = text;
01119        QFile f(QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + nam + ".sce")));
01120        if(!f.open(IO_WriteOnly))
01121               return ;
01122        QTextStream s;
01123        QCString cs = ff.utf8();
01124        s.setEncoding(QTextStream::UnicodeUTF8);
01125        s.setDevice(&f);
01126        s.writeRawBytes(cs.data(), cs.length());
01127        f.close();
01128        ScPreview *pre = new ScPreview();
01129        QPixmap pm = pre->createPreview(ff);
01130        activeBView->AddObj(nam, QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + nam + ".sce")), pm);
01131        pm.save(QDir::cleanDirPath(QDir::convertSeparators(activeBView->ScFilename + "/" + nam +".png")), "PNG");
01132        (void) new QIconViewItem(activeBView, nam, pm);
01133        delete pre;
01134 //     if (Frame3->currentPageIndex() == 1)
01135        if (Frame3->currentIndex() == 1)
01136        {
01137               if (tempBView->objectMap.count() > static_cast<uint>(PrefsManager::instance()->appPrefs.numScrapbookCopies))
01138               {
01139                      QMap<QString,BibView::Elem>::Iterator it;
01140                      it = tempBView->objectMap.begin();
01141                      QFile f(it.data().Data);
01142                      f.remove();
01143                      QFileInfo fi(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
01144                      if (fi.exists())
01145                      {
01146                             QFile f2(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
01147                             f2.remove();
01148                      }
01149                      QFileInfo fiD(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
01150                      if ((fiD.exists()) && (fiD.isDir()))
01151                      {
01152                             QDir dd = QDir(QDir::convertSeparators(tempBView->ScFilename));
01153                             QDir d(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
01154                             if ((d.exists()) && (d.count() != 0))
01155                             {
01156                                    for (uint dc = 0; dc < d.count(); ++dc)
01157                                    {
01158                                           QFile::remove(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + "/" + d[dc]));
01159                                    }
01160                             }
01161                             dd.rmdir(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
01162                      }
01163                      tempBView->objectMap.remove(it);
01164                      QIconViewItem* ite = tempBView->firstItem();
01165                      if (ite != 0)
01166                             delete ite;
01167                      tempBView->sort(activeBView->sortDirection());
01168                      tempBView->arrangeItemsInGrid(true);
01169               }
01170               emit updateRecentMenue();
01171        }
01172 }
01173 
01174 void Biblio::ObjFromCopyAction(QString text)
01175 {
01176        QString nam, tmp;
01177        nam = tr("Object") + tmp.setNum(tempCount);
01178        tempCount++;
01179        QString ff = text;
01180        QFile f(QDir::cleanDirPath(QDir::convertSeparators(tempBView->ScFilename + "/" + nam + ".sce")));
01181        if(!f.open(IO_WriteOnly))
01182               return ;
01183        QTextStream s;
01184        QCString cs = ff.utf8();
01185        s.setEncoding(QTextStream::UnicodeUTF8);
01186        s.setDevice(&f);
01187        s.writeRawBytes(cs.data(), cs.length());
01188        f.close();
01189        ScPreview *pre = new ScPreview();
01190        QPixmap pm = pre->createPreview(ff);
01191        tempBView->AddObj(nam, QDir::cleanDirPath(QDir::convertSeparators(tempBView->ScFilename + "/" + nam + ".sce")), pm);
01192        pm.save(QDir::cleanDirPath(QDir::convertSeparators(tempBView->ScFilename + "/" + nam +".png")), "PNG");
01193        (void) new QIconViewItem(tempBView, nam, pm);
01194        delete pre;
01195        if (tempBView->objectMap.count() > static_cast<uint>(PrefsManager::instance()->appPrefs.numScrapbookCopies))
01196        {
01197               QMap<QString,BibView::Elem>::Iterator it;
01198               it = tempBView->objectMap.begin();
01199               QFile f(it.data().Data);
01200               f.remove();
01201               QFileInfo fi(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
01202               if (fi.exists())
01203               {
01204                      QFile f2(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
01205                      f2.remove();
01206               }
01207               QFileInfo fiD(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
01208               if ((fiD.exists()) && (fiD.isDir()))
01209               {
01210                      QDir dd = QDir(QDir::convertSeparators(tempBView->ScFilename));
01211                      QDir d(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
01212                      if ((d.exists()) && (d.count() != 0))
01213                      {
01214                             for (uint dc = 0; dc < d.count(); ++dc)
01215                             {
01216                                    QFile::remove(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + "/" + d[dc]));
01217                             }
01218                      }
01219                      dd.rmdir(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
01220               }
01221               tempBView->objectMap.remove(it);
01222               QIconViewItem* ite = tempBView->firstItem();
01223               if (ite != 0)
01224                      delete ite;
01225               tempBView->sort(tempBView->sortDirection());
01226               tempBView->arrangeItemsInGrid(true);
01227        }
01228 }
01229 
01230 void Biblio::CleanUpTemp()
01231 {
01232        QMap<QString,BibView::Elem>::Iterator it;
01233        for (it = tempBView->objectMap.begin(); it != tempBView->objectMap.end(); ++it)
01234        {
01235               QFile f(it.data().Data);
01236               f.remove();
01237               QFileInfo fi(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
01238               if (fi.exists())
01239               {
01240                      QFile f2(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + ".png"));
01241                      f2.remove();
01242               }
01243               QFileInfo fiD(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
01244               if ((fiD.exists()) && (fiD.isDir()))
01245               {
01246                      QDir dd = QDir(QDir::convertSeparators(tempBView->ScFilename));
01247                      QDir d(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
01248                      if ((d.exists()) && (d.count() != 0))
01249                      {
01250                             for (uint dc = 0; dc < d.count(); ++dc)
01251                             {
01252                                    QFile::remove(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key() + "/" + d[dc]));
01253                             }
01254                      }
01255                      dd.rmdir(QDir::convertSeparators(tempBView->ScFilename + "/" + it.key()));
01256               }
01257        }
01258 }
01259 
01260 void Biblio::languageChange()
01261 {
01262        setCaption( tr( "Scrapbook" ) );
01263        QToolTip::add( newButton, tr( "Create a new scrapbook page" ) );
01264        QToolTip::add( loadButton, tr( "Load an existing scrapbook" ) );
01265        QToolTip::add( saveAsButton, tr( "Save the selected scrapbook" ) );
01266        QToolTip::add( importButton, tr( "Import an scrapbook file from Scribus <=1.3.2" ) );
01267        QToolTip::add( closeButton, tr( "Close the selected scrapbook" ) );
01268 }