Rev 24034 | Rev 24038 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
14763 | cbradney | 7 | |
10862 | cbradney | 8 | #include "scrapbookpalette.h" |
10859 | cbradney | 9 | |
20185 | craig | 10 | #include <QAction> |
8571 | jghali | 11 | #include <QApplication> |
9535 | fschmid | 12 | #include <QByteArray> |
20185 | craig | 13 | #include <QCursor> |
14 | #include <QDataStream> |
||
15 | #include <QDomDocument> |
||
16 | #include <QDrag> |
||
8501 | cbradney | 17 | #include <QDropEvent> |
20185 | craig | 18 | #include <QEvent> |
9818 | fschmid | 19 | #include <QFile> |
20185 | craig | 20 | #include <QFileDialog> |
9818 | fschmid | 21 | #include <QFileInfo> |
20185 | craig | 22 | #include <QHBoxLayout> |
23 | #include <QKeyEvent> |
||
24 | #include <QMenu> |
||
9818 | fschmid | 25 | #include <QMessageBox> |
20185 | craig | 26 | #include <QMimeData> |
9819 | fschmid | 27 | #include <QPainter> |
20185 | craig | 28 | #include <QPixmap> |
14716 | fschmid | 29 | #include <QProgressDialog> |
23033 | jghali | 30 | #include <QSet> |
20185 | craig | 31 | #include <QSignalMapper> |
32 | #include <QSpacerItem> |
||
33 | #include <QToolBox> |
||
34 | #include <QToolButton> |
||
35 | #include <QToolTip> |
||
36 | #include <QUrl> |
||
37 | #include <QVBoxLayout> |
||
11269 | fschmid | 38 | |
20185 | craig | 39 | #include "cmsettings.h" |
11605 | jghali | 40 | #include "commonstrings.h" |
20185 | craig | 41 | #include "fileloader.h" |
15526 | fschmid | 42 | #include "filewatcher.h" |
20185 | craig | 43 | #include "iconmanager.h" |
44 | #include "loadsaveplugin.h" |
||
45 | #include "plugins/formatidlist.h" |
||
415 | Franz | 46 | #include "prefsfile.h" |
2834 | cbradney | 47 | #include "prefsmanager.h" |
11605 | jghali | 48 | #include "query.h" |
20185 | craig | 49 | #include "scimage.h" |
21526 | craig | 50 | #include "scpaths.h" |
11605 | jghali | 51 | #include "scpreview.h" |
23474 | jghali | 52 | #include "scribusapp.h" |
14716 | fschmid | 53 | #include "scribuscore.h" |
11605 | jghali | 54 | #include "util.h" |
15525 | fschmid | 55 | #include "util_color.h" |
11605 | jghali | 56 | #include "util_file.h" |
15525 | fschmid | 57 | #include "util_formats.h" |
20185 | craig | 58 | |
2856 | cbradney | 59 | //CB TODO bring in the prefsManager instance locally here too |
2534 | craig | 60 | |
3 | paul | 61 | /* The Scrapbook View Class |
9818 | fschmid | 62 | * inherited from QListWidget */ |
63 | BibView::BibView(QWidget* parent) : QListWidget(parent) |
||
3 | paul | 64 | { |
9818 | fschmid | 65 | setDragEnabled(true); |
66 | setViewMode(QListView::IconMode); |
||
67 | setFlow(QListView::LeftToRight); |
||
15533 | fschmid | 68 | // setSortingEnabled(true); |
9818 | fschmid | 69 | setWrapping(true); |
70 | setAcceptDrops(true); |
||
71 | setDropIndicatorShown(true); |
||
72 | setDragDropMode(QAbstractItemView::DragDrop); |
||
73 | setResizeMode(QListView::Adjust); |
||
74 | setSelectionMode(QAbstractItemView::SingleSelection); |
||
75 | setContextMenuPolicy(Qt::CustomContextMenu); |
||
9819 | fschmid | 76 | setIconSize(QSize(60, 60)); |
15552 | fschmid | 77 | setGridSize(QSize(70, 80)); |
78 | setSpacing(10); |
||
79 | setTextElideMode(Qt::ElideMiddle); |
||
2144 | cbradney | 80 | objectMap.clear(); |
4643 | fschmid | 81 | ScFilename = ""; |
15516 | fschmid | 82 | visibleName = ""; |
9819 | fschmid | 83 | canWrite = true; |
3 | paul | 84 | } |
9819 | fschmid | 85 | |
9818 | fschmid | 86 | void BibView::startDrag(Qt::DropActions supportedActions) |
87 | { |
||
18297 | fschmid | 88 | QStringList vectorFiles = LoadSavePlugin::getExtensionsForPreview(FORMATID_FIRSTUSER); |
15525 | fschmid | 89 | QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::RASTORIMAGES, 1)); |
90 | QStringList rasterFiles = formatD.split("|"); |
||
6028 | jghali | 91 | QString dt = objectMap[currentItem()->text()].Data; |
4708 | fschmid | 92 | QFileInfo fi(dt); |
14768 | fschmid | 93 | QMimeData *mimeData = new QMimeData; |
94 | QList<QUrl> urlList; |
||
16171 | fschmid | 95 | if (fi.suffix().toLower() == "sce") |
4708 | fschmid | 96 | { |
22708 | jghali | 97 | if (fi.exists()) |
8288 | fschmid | 98 | { |
12045 | jghali | 99 | QUrl ur = QUrl::fromLocalFile(dt); |
14768 | fschmid | 100 | urlList.append(ur); |
101 | mimeData->setUrls(urlList); |
||
8288 | fschmid | 102 | } |
4735 | fschmid | 103 | } |
15525 | fschmid | 104 | else if ((vectorFiles.contains(fi.suffix().toLower())) || (rasterFiles.contains(fi.suffix().toLower()))) |
14678 | fschmid | 105 | { |
22708 | jghali | 106 | if (fi.exists()) |
14678 | fschmid | 107 | { |
108 | QUrl ur = QUrl::fromLocalFile(dt); |
||
14768 | fschmid | 109 | urlList.append(ur); |
110 | mimeData->setUrls(urlList); |
||
14678 | fschmid | 111 | } |
112 | } |
||
9818 | fschmid | 113 | QDrag *drag = new QDrag(this); |
114 | drag->setMimeData(mimeData); |
||
15060 | fschmid | 115 | drag->setPixmap(objectMap[currentItem()->text()].Preview); |
10643 | fschmid | 116 | drag->exec(Qt::CopyAction); |
4649 | fschmid | 117 | clearSelection(); |
9818 | fschmid | 118 | } |
119 | |||
120 | void BibView::dragEnterEvent(QDragEnterEvent *e) |
||
121 | { |
||
122 | if (e->source() == this) |
||
123 | e->ignore(); |
||
124 | else |
||
125 | e->acceptProposedAction(); |
||
3 | paul | 126 | } |
127 | |||
9818 | fschmid | 128 | void BibView::dragMoveEvent(QDragMoveEvent *e) |
129 | { |
||
130 | if (e->source() == this) |
||
131 | e->ignore(); |
||
132 | else |
||
133 | e->acceptProposedAction(); |
||
134 | } |
||
135 | |||
136 | void BibView::dropEvent(QDropEvent *e) |
||
137 | { |
||
138 | if (e->mimeData()->hasText()) |
||
139 | { |
||
140 | e->acceptProposedAction(); |
||
141 | if (e->source() == this) |
||
142 | return; |
||
143 | QString text = e->mimeData()->text(); |
||
22638 | craig | 144 | int startElemPos = text.leftRef(512).indexOf("<SCRIBUSELEM"); |
17003 | fschmid | 145 | if (startElemPos >= 0) |
9818 | fschmid | 146 | emit objDropped(text); |
147 | } |
||
22708 | jghali | 148 | else if (e->mimeData()->hasFormat("text/uri-list")) |
14715 | fschmid | 149 | { |
18297 | fschmid | 150 | QStringList vectorFiles = LoadSavePlugin::getExtensionsForPreview(FORMATID_FIRSTUSER); |
15525 | fschmid | 151 | QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::RASTORIMAGES, 1)); |
152 | QStringList rasterFiles = formatD.split("|"); |
||
14715 | fschmid | 153 | QList<QUrl> fileUrls = e->mimeData()->urls(); |
154 | e->acceptProposedAction(); |
||
22708 | jghali | 155 | for (int i = 0; i < fileUrls.count(); ++i) |
14715 | fschmid | 156 | { |
22708 | jghali | 157 | QUrl url(fileUrls[i] ); |
14715 | fschmid | 158 | QFileInfo fi(url.path()); |
159 | if (vectorFiles.contains(fi.suffix().toLower())) |
||
160 | { |
||
161 | FileLoader *fileLoader = new FileLoader(url.path()); |
||
17326 | jghali | 162 | int testResult = fileLoader->testFile(); |
14715 | fschmid | 163 | delete fileLoader; |
18297 | fschmid | 164 | if ((testResult != -1) && (testResult >= FORMATID_FIRSTUSER) && (fi.exists())) |
14715 | fschmid | 165 | emit fileDropped(url.path(), testResult); |
166 | } |
||
15525 | fschmid | 167 | else if (rasterFiles.contains(fi.suffix().toLower())) |
168 | emit fileDropped(url.path(), 9999); |
||
14715 | fschmid | 169 | } |
170 | } |
||
9818 | fschmid | 171 | else |
172 | e->ignore(); |
||
173 | } |
||
174 | |||
23035 | jghali | 175 | void BibView::addObject(const QString& name, const QString& daten, const QPixmap& Bild, bool isDir, bool isRaster, bool isVector) |
3 | paul | 176 | { |
177 | struct Elem DrElem; |
||
15533 | fschmid | 178 | DrElem.isDir = isDir; |
179 | DrElem.isRaster = isRaster; |
||
15552 | fschmid | 180 | DrElem.isVector = isVector; |
248 | Franz | 181 | DrElem.Data = daten; |
182 | DrElem.Preview = Bild; |
||
2144 | cbradney | 183 | objectMap.insert(name, DrElem); |
3 | paul | 184 | } |
185 | |||
22635 | craig | 186 | void BibView::checkForImg(const QDomElement& elem, bool &hasImage) |
18478 | fschmid | 187 | { |
22708 | jghali | 188 | QDomNode node = elem.firstChild(); |
189 | while (!node.isNull()) |
||
18478 | fschmid | 190 | { |
22708 | jghali | 191 | QDomElement pg = node.toElement(); |
192 | if (pg.tagName() == "PAGEOBJECT") |
||
18478 | fschmid | 193 | { |
194 | PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt()); |
||
195 | if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame)) |
||
196 | { |
||
197 | QString Pfile = pg.attribute("PFILE"); |
||
198 | QString Pfile2 = pg.attribute("PFILE2",""); |
||
199 | QString Pfile3 = pg.attribute("PFILE3",""); |
||
200 | if (!Pfile.isEmpty()) |
||
201 | hasImage = true; |
||
202 | if (!Pfile2.isEmpty()) |
||
203 | hasImage = true; |
||
204 | if (!Pfile3.isEmpty()) |
||
205 | hasImage = true; |
||
206 | } |
||
18483 | fschmid | 207 | else if (PType == PageItem::OSGFrame) |
208 | { |
||
209 | QString Pfile = pg.attribute("modelFile"); |
||
210 | if (!Pfile.isEmpty()) |
||
211 | hasImage = true; |
||
212 | } |
||
18478 | fschmid | 213 | else if (PType == PageItem::Group) |
214 | checkForImg(pg, hasImage); |
||
18483 | fschmid | 215 | if (hasImage) |
216 | break; |
||
18478 | fschmid | 217 | } |
22708 | jghali | 218 | node = node.nextSibling(); |
18478 | fschmid | 219 | } |
220 | } |
||
221 | |||
22635 | craig | 222 | void BibView::checkAndChange(const QString& text, const QString& nam, const QString& dir) |
8288 | fschmid | 223 | { |
18478 | fschmid | 224 | bool hasImage = false; |
8288 | fschmid | 225 | QDomDocument docu("scridoc"); |
226 | docu.setContent(text); |
||
227 | QDomElement elem = docu.documentElement(); |
||
22708 | jghali | 228 | QDomNode node = elem.firstChild(); |
229 | while (!node.isNull()) |
||
8288 | fschmid | 230 | { |
22708 | jghali | 231 | QDomElement pg = node.toElement(); |
232 | if (pg.tagName() == "ITEM") |
||
8288 | fschmid | 233 | { |
234 | PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt()); |
||
235 | if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame)) |
||
236 | { |
||
237 | QString Pfile = pg.attribute("PFILE"); |
||
238 | QString Pfile2 = pg.attribute("PFILE2",""); |
||
239 | QString Pfile3 = pg.attribute("PFILE3",""); |
||
240 | if (!Pfile.isEmpty()) |
||
241 | hasImage = true; |
||
242 | if (!Pfile2.isEmpty()) |
||
243 | hasImage = true; |
||
244 | if (!Pfile3.isEmpty()) |
||
245 | hasImage = true; |
||
246 | } |
||
18483 | fschmid | 247 | else if (PType == PageItem::OSGFrame) |
248 | { |
||
249 | QString Pfile = pg.attribute("modelFile"); |
||
250 | if (!Pfile.isEmpty()) |
||
251 | hasImage = true; |
||
252 | } |
||
18478 | fschmid | 253 | else if (PType == PageItem::Group) |
254 | checkForImg(pg, hasImage); |
||
18483 | fschmid | 255 | if (hasImage) |
256 | break; |
||
8288 | fschmid | 257 | } |
22708 | jghali | 258 | node = node.nextSibling(); |
8288 | fschmid | 259 | } |
260 | QFileInfo fid(nam); |
||
261 | if (hasImage) |
||
262 | { |
||
263 | QDir dd = QDir(dir); |
||
16577 | craig | 264 | dd.mkdir(QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName()))); |
8288 | fschmid | 265 | } |
8295 | fschmid | 266 | QString source = ""; |
21864 | jghali | 267 | QString fileDir = ScPaths::applicationDataDir(); |
11548 | fschmid | 268 | bool first = true; |
22708 | jghali | 269 | node = elem.firstChild(); |
270 | while (!node.isNull()) |
||
8288 | fschmid | 271 | { |
22708 | jghali | 272 | QDomElement pg = node.toElement(); |
21864 | jghali | 273 | if (pg.tagName() == "ITEM") |
8288 | fschmid | 274 | { |
11548 | fschmid | 275 | if (first) |
276 | pg.setAttribute("ANNAME", fid.baseName()); |
||
277 | first = false; |
||
8288 | fschmid | 278 | PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt()); |
279 | if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame)) |
||
280 | { |
||
281 | QString Pfile = pg.attribute("PFILE"); |
||
282 | if (!Pfile.isEmpty()) |
||
283 | { |
||
17960 | jghali | 284 | QFileInfo fi(Pfile); |
285 | if (fi.isAbsolute()) |
||
286 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile)); |
||
287 | else |
||
8288 | fschmid | 288 | { |
18478 | fschmid | 289 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile))); |
10564 | fschmid | 290 | source = pfi2.absoluteFilePath(); |
8288 | fschmid | 291 | } |
16577 | craig | 292 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
8288 | fschmid | 293 | copyFile(source, target); |
294 | pg.setAttribute("PFILE", fid.baseName() + "/" + fi.fileName()); |
||
295 | } |
||
296 | QString Pfile2 = pg.attribute("PFILE2",""); |
||
297 | if (!Pfile2.isEmpty()) |
||
298 | { |
||
17960 | jghali | 299 | QFileInfo fi(Pfile2); |
300 | if (fi.isAbsolute()) |
||
301 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile2)); |
||
302 | else |
||
8288 | fschmid | 303 | { |
18478 | fschmid | 304 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile2))); |
10564 | fschmid | 305 | source = pfi2.absoluteFilePath(); |
8288 | fschmid | 306 | } |
16577 | craig | 307 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
8288 | fschmid | 308 | copyFile(source, target); |
8295 | fschmid | 309 | pg.setAttribute("PFILE2", fid.baseName() + "/" + fi.fileName()); |
8288 | fschmid | 310 | } |
311 | QString Pfile3 = pg.attribute("PFILE3",""); |
||
312 | if (!Pfile3.isEmpty()) |
||
313 | { |
||
17960 | jghali | 314 | QFileInfo fi(Pfile3); |
315 | if (fi.isAbsolute()) |
||
316 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile3)); |
||
317 | else |
||
8288 | fschmid | 318 | { |
18478 | fschmid | 319 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile3))); |
10564 | fschmid | 320 | source = pfi2.absoluteFilePath(); |
8288 | fschmid | 321 | } |
16577 | craig | 322 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
8288 | fschmid | 323 | copyFile(source, target); |
8295 | fschmid | 324 | pg.setAttribute("PFILE3", fid.baseName() + "/" + fi.fileName()); |
8288 | fschmid | 325 | } |
326 | pg.setAttribute("relativePaths", 1); |
||
327 | } |
||
18483 | fschmid | 328 | else if (PType == PageItem::OSGFrame) |
329 | { |
||
330 | QString Pfile = pg.attribute("modelFile"); |
||
331 | if (!Pfile.isEmpty()) |
||
332 | { |
||
333 | QFileInfo fi(Pfile); |
||
334 | if (fi.isAbsolute()) |
||
335 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile)); |
||
336 | else |
||
337 | { |
||
338 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile))); |
||
339 | source = pfi2.absoluteFilePath(); |
||
340 | } |
||
341 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
||
342 | copyFile(source, target); |
||
343 | pg.setAttribute("modelFile", fid.baseName() + "/" + fi.fileName()); |
||
344 | } |
||
345 | } |
||
18478 | fschmid | 346 | else if (PType == PageItem::Group) |
347 | { |
||
348 | checkAndChangeGroups(pg, dir, fid); |
||
349 | } |
||
8288 | fschmid | 350 | } |
22708 | jghali | 351 | node = node.nextSibling(); |
8288 | fschmid | 352 | } |
353 | QFile f(nam); |
||
22708 | jghali | 354 | if (!f.open(QIODevice::WriteOnly)) |
8288 | fschmid | 355 | return ; |
9818 | fschmid | 356 | QDataStream s; |
8571 | jghali | 357 | QByteArray cs = docu.toByteArray(); |
8288 | fschmid | 358 | s.setDevice(&f); |
10564 | fschmid | 359 | s.writeRawData(cs.data(), cs.length()); |
8288 | fschmid | 360 | f.close(); |
361 | } |
||
16171 | fschmid | 362 | |
22635 | craig | 363 | void BibView::checkAndChangeGroups(const QDomElement& elem, const QString& dir, const QFileInfo& fid) |
18478 | fschmid | 364 | { |
22635 | craig | 365 | QString source; |
21864 | jghali | 366 | QString fileDir = ScPaths::applicationDataDir(); |
22708 | jghali | 367 | QDomNode node = elem.firstChild(); |
368 | while (!node.isNull()) |
||
18478 | fschmid | 369 | { |
22708 | jghali | 370 | QDomElement pg = node.toElement(); |
21864 | jghali | 371 | if (pg.tagName() == "PAGEOBJECT") |
18478 | fschmid | 372 | { |
373 | PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt()); |
||
374 | if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame)) |
||
375 | { |
||
376 | QString Pfile = pg.attribute("PFILE"); |
||
377 | if (!Pfile.isEmpty()) |
||
378 | { |
||
379 | QFileInfo fi(Pfile); |
||
380 | if (fi.isAbsolute()) |
||
381 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile)); |
||
382 | else |
||
383 | { |
||
384 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile))); |
||
385 | source = pfi2.absoluteFilePath(); |
||
386 | } |
||
387 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
||
388 | copyFile(source, target); |
||
389 | pg.setAttribute("PFILE", fid.baseName() + "/" + fi.fileName()); |
||
390 | } |
||
391 | QString Pfile2 = pg.attribute("PFILE2",""); |
||
392 | if (!Pfile2.isEmpty()) |
||
393 | { |
||
394 | QFileInfo fi(Pfile2); |
||
395 | if (fi.isAbsolute()) |
||
396 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile2)); |
||
397 | else |
||
398 | { |
||
399 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile2))); |
||
400 | source = pfi2.absoluteFilePath(); |
||
401 | } |
||
402 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
||
403 | copyFile(source, target); |
||
404 | pg.setAttribute("PFILE2", fid.baseName() + "/" + fi.fileName()); |
||
405 | } |
||
406 | QString Pfile3 = pg.attribute("PFILE3",""); |
||
407 | if (!Pfile3.isEmpty()) |
||
408 | { |
||
409 | QFileInfo fi(Pfile3); |
||
410 | if (fi.isAbsolute()) |
||
411 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile3)); |
||
412 | else |
||
413 | { |
||
414 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile3))); |
||
415 | source = pfi2.absoluteFilePath(); |
||
416 | } |
||
417 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
||
418 | copyFile(source, target); |
||
419 | pg.setAttribute("PFILE3", fid.baseName() + "/" + fi.fileName()); |
||
420 | } |
||
421 | pg.setAttribute("relativePaths", 1); |
||
422 | } |
||
18483 | fschmid | 423 | else if (PType == PageItem::OSGFrame) |
424 | { |
||
425 | QString Pfile = pg.attribute("modelFile"); |
||
426 | if (!Pfile.isEmpty()) |
||
427 | { |
||
428 | QFileInfo fi(Pfile); |
||
429 | if (fi.isAbsolute()) |
||
430 | source = QDir::cleanPath(QDir::toNativeSeparators(Pfile)); |
||
431 | else |
||
432 | { |
||
433 | QFileInfo pfi2(QDir::cleanPath(QDir::toNativeSeparators(fileDir+"/"+Pfile))); |
||
434 | source = pfi2.absoluteFilePath(); |
||
435 | } |
||
436 | QString target = QDir::cleanPath(QDir::toNativeSeparators(dir + "/" + fid.baseName() + "/" + fi.fileName())); |
||
437 | copyFile(source, target); |
||
438 | pg.setAttribute("modelFile", fid.baseName() + "/" + fi.fileName()); |
||
439 | } |
||
440 | } |
||
18478 | fschmid | 441 | else if (PType == PageItem::Group) |
442 | { |
||
443 | checkAndChangeGroups(pg, dir, fid); |
||
444 | } |
||
445 | } |
||
22708 | jghali | 446 | node = node.nextSibling(); |
18478 | fschmid | 447 | } |
448 | } |
||
449 | |||
23035 | jghali | 450 | void BibView::readOldContents(const QString& name, const QString& newName) |
3 | paul | 451 | { |
6062 | jghali | 452 | bool isUtf8 = false; |
3 | paul | 453 | QDomDocument docu("scridoc"); |
6062 | jghali | 454 | QString ff; |
9535 | fschmid | 455 | QByteArray cf; |
6062 | jghali | 456 | if (!loadRawText(name, cf)) |
3 | paul | 457 | return; |
22708 | jghali | 458 | if (cf.left(17) == "<SCRIBUSSCRAPUTF8") |
6062 | jghali | 459 | { |
460 | ff = QString::fromUtf8(cf.data()); |
||
461 | isUtf8 = true; |
||
462 | } |
||
463 | else |
||
464 | ff = QString::fromLocal8Bit(cf.data()); |
||
22708 | jghali | 465 | if (!docu.setContent(ff)) |
3 | paul | 466 | return; |
22708 | jghali | 467 | QDomElement elem = docu.documentElement(); |
3 | paul | 468 | if ((elem.tagName() != "SCRIBUSSCRAP") && (elem.tagName() != "SCRIBUSSCRAPUTF8")) |
469 | return; |
||
22708 | jghali | 470 | QDomNode node = elem.firstChild(); |
471 | while (!node.isNull()) |
||
248 | Franz | 472 | { |
22708 | jghali | 473 | QDomElement dc=node.toElement(); |
3 | paul | 474 | if (dc.tagName()=="OBJEKT") |
248 | Franz | 475 | { |
22631 | craig | 476 | QFile fi(QDir::cleanPath(QDir::toNativeSeparators(newName + "/" + dc.attribute("NAME", nullptr) + ".sce"))); |
22708 | jghali | 477 | if (!fi.open(QIODevice::WriteOnly)) |
4611 | fschmid | 478 | continue ; |
9818 | fschmid | 479 | QDataStream s(&fi); |
22631 | craig | 480 | QString fn = dc.attribute("DATA", nullptr); |
10493 | fschmid | 481 | cf = isUtf8? fn.toUtf8() : fn.toLocal8Bit(); |
10564 | fschmid | 482 | s.writeRawData(cf.data(), cf.length()); |
4611 | fschmid | 483 | fi.close(); |
484 | } |
||
22708 | jghali | 485 | node = node.nextSibling(); |
4611 | fschmid | 486 | } |
487 | } |
||
488 | |||
23035 | jghali | 489 | void BibView::readContents(const QString& name) |
4611 | fschmid | 490 | { |
14716 | fschmid | 491 | int fileCount = 0; |
492 | int readCount = 0; |
||
23033 | jghali | 493 | QSet<QString> vectorFound; |
494 | QSet<QString> rasterFound; |
||
23036 | jghali | 495 | |
496 | clear(); |
||
497 | objectMap.clear(); |
||
498 | |||
499 | QString dirPath = QDir::cleanPath(QDir::toNativeSeparators(name)); |
||
500 | while ((dirPath.length() > 1) && dirPath.endsWith("/")) |
||
501 | dirPath.chop(1); |
||
502 | |||
503 | QDir thumbs(dirPath); |
||
15520 | fschmid | 504 | if (thumbs.exists()) |
505 | { |
||
23060 | craig | 506 | if ((canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
15520 | fschmid | 507 | thumbs.mkdir(".ScribusThumbs"); |
508 | thumbs.cd(".ScribusThumbs"); |
||
509 | } |
||
23036 | jghali | 510 | QDir dd(dirPath, "*", QDir::Name, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable | QDir::NoSymLinks); |
15533 | fschmid | 511 | fileCount += dd.count(); |
23036 | jghali | 512 | QDir d(dirPath, "*.sce", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
15520 | fschmid | 513 | fileCount += d.count(); |
18297 | fschmid | 514 | QStringList vectorFiles = LoadSavePlugin::getExtensionsForPreview(FORMATID_FIRSTUSER); |
14716 | fschmid | 515 | for (int v = 0; v < vectorFiles.count(); v++) |
516 | { |
||
517 | QString ext = "*." + vectorFiles[v]; |
||
23036 | jghali | 518 | QDir d4(dirPath, ext, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
14716 | fschmid | 519 | fileCount += d4.count(); |
23033 | jghali | 520 | if (d4.count() > 0) |
521 | vectorFound.insert(vectorFiles[v]); |
||
14716 | fschmid | 522 | } |
15525 | fschmid | 523 | QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::RASTORIMAGES, 1)); |
524 | QStringList rasterFiles = formatD.split("|"); |
||
525 | for (int v = 0; v < rasterFiles.count(); v++) |
||
526 | { |
||
527 | QString ext = "*." + rasterFiles[v]; |
||
23036 | jghali | 528 | QDir d5(dirPath, ext, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
15525 | fschmid | 529 | fileCount += d5.count(); |
23033 | jghali | 530 | if (d5.count() > 0) |
531 | rasterFound.insert(rasterFiles[v]); |
||
15525 | fschmid | 532 | } |
22516 | craig | 533 | QProgressDialog *pgDia = nullptr; |
15527 | fschmid | 534 | QStringList previewFiles; |
535 | previewFiles.clear(); |
||
14716 | fschmid | 536 | if (ScCore->initialized()) |
537 | { |
||
538 | pgDia = new QProgressDialog("Reading Files...", QString(), 0, fileCount, this); |
||
539 | pgDia->setWindowModality(Qt::WindowModal); |
||
540 | } |
||
15533 | fschmid | 541 | if ((dd.exists()) && (dd.count() != 0)) |
542 | { |
||
543 | for (uint dc = 0; dc < dd.count(); ++dc) |
||
544 | { |
||
545 | if (pgDia) |
||
546 | { |
||
547 | pgDia->setValue(readCount); |
||
548 | readCount++; |
||
549 | } |
||
18078 | jghali | 550 | if (dd[dc].compare(".ScribusThumbs", Qt::CaseInsensitive) == 0) |
551 | continue; |
||
23054 | craig | 552 | QPixmap pm = IconManager::instance().loadPixmap("folder.png"); |
23035 | jghali | 553 | addObject(dd[dc], "", pm, true); |
15533 | fschmid | 554 | } |
555 | } |
||
4611 | fschmid | 556 | if ((d.exists()) && (d.count() != 0)) |
557 | { |
||
558 | for (uint dc = 0; dc < d.count(); ++dc) |
||
559 | { |
||
14716 | fschmid | 560 | if (pgDia) |
561 | { |
||
562 | pgDia->setValue(readCount); |
||
563 | readCount++; |
||
564 | } |
||
4649 | fschmid | 565 | QPixmap pm; |
9535 | fschmid | 566 | QByteArray cf; |
23036 | jghali | 567 | if (!loadRawText(QDir::cleanPath(dirPath + "/" + d[dc]), cf)) |
4611 | fschmid | 568 | continue; |
23036 | jghali | 569 | QFileInfo fi(QDir::cleanPath(dirPath + "/" + d[dc])); |
570 | QString filePath = QDir::cleanPath(QDir::toNativeSeparators(fi.path())); |
||
571 | bool pngExists = QFile::exists(filePath + "/.ScribusThumbs/" + fi.baseName() + ".png"); |
||
23033 | jghali | 572 | if (pngExists) |
23036 | jghali | 573 | pm.load(filePath + "/.ScribusThumbs/" + fi.baseName() + ".png"); |
4649 | fschmid | 574 | else |
575 | { |
||
23036 | jghali | 576 | pngExists = QFile::exists(filePath + "/" + fi.baseName() + ".png"); |
23033 | jghali | 577 | if (pngExists) |
23036 | jghali | 578 | pm.load(filePath + "/" + fi.baseName() + ".png"); |
6062 | jghali | 579 | else |
15527 | fschmid | 580 | { |
581 | QString f; |
||
582 | if (cf.left(16) == "<SCRIBUSELEMUTF8") |
||
583 | f = QString::fromUtf8(cf.data()); |
||
584 | else |
||
585 | f = cf.data(); |
||
586 | ScPreview *pre = new ScPreview(); |
||
587 | pm = QPixmap::fromImage(pre->createPreview(f)); |
||
23060 | craig | 588 | if ((canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
23036 | jghali | 589 | pm.save(filePath + "/.ScribusThumbs/" + fi.baseName() + ".png", "PNG"); |
15527 | fschmid | 590 | delete pre; |
591 | } |
||
4649 | fschmid | 592 | } |
23034 | jghali | 593 | previewFiles.append(fi.baseName() + ".png"); |
23036 | jghali | 594 | addObject(fi.baseName(), QDir::cleanPath(dirPath + "/" + d[dc]), pm); |
248 | Franz | 595 | } |
596 | } |
||
14678 | fschmid | 597 | for (int v = 0; v < vectorFiles.count(); v++) |
598 | { |
||
23033 | jghali | 599 | if (!vectorFound.contains(vectorFiles[v])) |
600 | continue; |
||
14678 | fschmid | 601 | QString ext = "*." + vectorFiles[v]; |
23036 | jghali | 602 | QDir d4(dirPath, ext, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
19228 | jghali | 603 | if ((!d4.exists()) || (d4.count() <= 0)) |
604 | continue; |
||
605 | for (uint dc = 0; dc < d4.count(); ++dc) |
||
14678 | fschmid | 606 | { |
19228 | jghali | 607 | if (pgDia) |
14678 | fschmid | 608 | { |
19228 | jghali | 609 | pgDia->setValue(readCount); |
610 | readCount++; |
||
611 | } |
||
612 | QPixmap pm; |
||
23036 | jghali | 613 | QFileInfo fi(QDir::cleanPath(dirPath + "/" + d4[dc])); |
614 | QString filePath = QDir::cleanPath(QDir::toNativeSeparators(fi.path())); |
||
615 | bool pngExists = QFile::exists(filePath + "/.ScribusThumbs/" + fi.fileName() + ".png"); |
||
23033 | jghali | 616 | if (pngExists) |
23036 | jghali | 617 | pm.load(filePath + "/.ScribusThumbs/" + fi.fileName() + ".png"); |
19228 | jghali | 618 | else |
619 | { |
||
23036 | jghali | 620 | FileLoader *fileLoader = new FileLoader(QDir::cleanPath(dirPath + "/" + d4[dc])); |
19228 | jghali | 621 | int testResult = fileLoader->testFile(); |
622 | delete fileLoader; |
||
623 | if ((testResult != -1) && (testResult >= FORMATID_FIRSTUSER)) |
||
14716 | fschmid | 624 | { |
19228 | jghali | 625 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
22708 | jghali | 626 | if (fmt) |
14678 | fschmid | 627 | { |
23036 | jghali | 628 | QImage im = fmt->readThumbnail(dirPath + "/" + d4[dc]); |
19228 | jghali | 629 | im = im.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
23060 | craig | 630 | if ((canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
23036 | jghali | 631 | im.save(filePath + "/.ScribusThumbs/" + fi.fileName() + ".png", "PNG"); |
19228 | jghali | 632 | pm = QPixmap::fromImage(im); |
14678 | fschmid | 633 | } |
634 | } |
||
635 | } |
||
23036 | jghali | 636 | addObject(fi.fileName(), QDir::cleanPath(dirPath + "/" + d4[dc]), pm, false, false, true); |
14678 | fschmid | 637 | } |
638 | } |
||
15525 | fschmid | 639 | for (int v = 0; v < rasterFiles.count(); v++) |
640 | { |
||
23033 | jghali | 641 | if (!rasterFound.contains(rasterFiles[v])) |
642 | continue; |
||
15525 | fschmid | 643 | QString ext = "*." + rasterFiles[v]; |
23036 | jghali | 644 | QDir d5(dirPath, ext, QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
19228 | jghali | 645 | if ((!d5.exists()) || (d5.count() <= 0)) |
646 | continue; |
||
647 | for (uint dc = 0; dc < d5.count(); ++dc) |
||
15525 | fschmid | 648 | { |
19228 | jghali | 649 | if (pgDia) |
15525 | fschmid | 650 | { |
19228 | jghali | 651 | pgDia->setValue(readCount); |
652 | readCount++; |
||
653 | } |
||
654 | if (previewFiles.contains(d5[dc])) |
||
655 | continue; |
||
656 | QPixmap pm; |
||
23036 | jghali | 657 | QFileInfo fi(QDir::cleanPath(dirPath + "/" + d5[dc])); |
658 | QString filePath = QDir::cleanPath(QDir::toNativeSeparators(fi.path())); |
||
659 | bool pngExists = QFile::exists(filePath + "/.ScribusThumbs/" + fi.fileName() + ".png"); |
||
23033 | jghali | 660 | if (pngExists) |
23036 | jghali | 661 | pm.load(filePath + "/.ScribusThumbs/" + fi.fileName() + ".png"); |
19228 | jghali | 662 | else |
663 | { |
||
664 | bool mode = false; |
||
665 | ScImage im; |
||
22631 | craig | 666 | CMSettings cms(nullptr, "", Intent_Perceptual); |
19228 | jghali | 667 | cms.allowColorManagement(false); |
23036 | jghali | 668 | if (im.loadPicture(dirPath + "/" + d5[dc], 1, cms, ScImage::Thumbnail, 72, &mode)) |
15525 | fschmid | 669 | { |
19228 | jghali | 670 | QImage img = im.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
23060 | craig | 671 | if ((canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
23036 | jghali | 672 | img.save(filePath + "/.ScribusThumbs/" + fi.fileName() + ".png", "PNG"); |
19228 | jghali | 673 | pm = QPixmap::fromImage(img); |
15525 | fschmid | 674 | } |
675 | } |
||
23036 | jghali | 676 | addObject(fi.fileName(), QDir::cleanPath(dirPath + "/" + d5[dc]), pm, false, true); |
15525 | fschmid | 677 | } |
678 | } |
||
14716 | fschmid | 679 | if (pgDia) |
680 | { |
||
681 | pgDia->setValue(fileCount); |
||
682 | delete pgDia; |
||
683 | } |
||
3 | paul | 684 | QMap<QString,Elem>::Iterator itf; |
2144 | cbradney | 685 | for (itf = objectMap.begin(); itf != objectMap.end(); ++itf) |
248 | Franz | 686 | { |
15533 | fschmid | 687 | if (itf.value().isDir) |
688 | { |
||
689 | QPixmap pm(60, 60); |
||
690 | pm.fill(palette().color(QPalette::Base)); |
||
691 | QPainter p; |
||
692 | p.begin(&pm); |
||
693 | p.drawPixmap(30 - itf.value().Preview.width() / 2, 30 - itf.value().Preview.height() / 2, itf.value().Preview); |
||
694 | p.end(); |
||
695 | QListWidgetItem *item = new QListWidgetItem(QIcon(pm), itf.key(), this); |
||
21181 | fschmid | 696 | item->setToolTip(itf.key()); |
15533 | fschmid | 697 | item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
15552 | fschmid | 698 | itf.value().widgetItem = item; |
15533 | fschmid | 699 | } |
248 | Franz | 700 | } |
15533 | fschmid | 701 | for (itf = objectMap.begin(); itf != objectMap.end(); ++itf) |
702 | { |
||
703 | if (!itf.value().isDir) |
||
704 | { |
||
705 | itf.value().Preview = itf.value().Preview.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
||
706 | QPixmap pm(60, 60); |
||
707 | pm.fill(palette().color(QPalette::Base)); |
||
708 | QPainter p; |
||
709 | p.begin(&pm); |
||
710 | p.drawPixmap(30 - itf.value().Preview.width() / 2, 30 - itf.value().Preview.height() / 2, itf.value().Preview); |
||
711 | p.end(); |
||
15552 | fschmid | 712 | QListWidgetItem *item = new QListWidgetItem(QIcon(pm), itf.key(), this); |
21181 | fschmid | 713 | item->setToolTip(itf.key()); |
15552 | fschmid | 714 | itf.value().widgetItem = item; |
15533 | fschmid | 715 | } |
716 | } |
||
3 | paul | 717 | } |
4693 | fschmid | 718 | |
3 | paul | 719 | /* This is the main Dialog-Class for the Scrapbook */ |
24027 | jghali | 720 | Biblio::Biblio(QWidget* parent) : ScDockPalette(parent, "Sclib", Qt::WindowFlags()) |
3 | paul | 721 | { |
16579 | fschmid | 722 | // resize( 230, 190 ); |
723 | setObjectName(QString::fromLocal8Bit("Sclib")); |
||
724 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); |
||
725 | containerWidget = new QWidget(this); |
||
726 | BiblioLayout = new QVBoxLayout( containerWidget ); |
||
248 | Franz | 727 | BiblioLayout->setSpacing( 0 ); |
1448 | cbradney | 728 | BiblioLayout->setMargin( 0 ); |
8336 | fschmid | 729 | |
9818 | fschmid | 730 | buttonLayout = new QHBoxLayout; |
5358 | cbradney | 731 | buttonLayout->setSpacing( 5 ); |
732 | buttonLayout->setMargin( 0 ); |
||
9818 | fschmid | 733 | newButton = new QToolButton(this); |
734 | newButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
||
23054 | craig | 735 | newButton->setIcon(IconManager::instance().loadPixmap("16/document-new.png")); |
9818 | fschmid | 736 | newButton->setIconSize(QSize(16, 16)); |
15533 | fschmid | 737 | upButton = new QToolButton(this); |
738 | upButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
||
23054 | craig | 739 | upButton->setIcon(IconManager::instance().loadPixmap("16/go-up.png")); |
15533 | fschmid | 740 | upButton->setIconSize(QSize(16, 16)); |
10564 | fschmid | 741 | importButton = new QToolButton(this); |
9818 | fschmid | 742 | importButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
23054 | craig | 743 | importButton->setIcon(IconManager::instance().loadPixmap("compfile16.png")); |
9818 | fschmid | 744 | importButton->setIconSize(QSize(16, 16)); |
10564 | fschmid | 745 | closeButton = new QToolButton(this); |
9818 | fschmid | 746 | closeButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
23054 | craig | 747 | closeButton->setIcon(IconManager::instance().loadPixmap("16/close.png")); |
9818 | fschmid | 748 | closeButton->setIconSize(QSize(16, 16)); |
15552 | fschmid | 749 | configButton = new QToolButton(this); |
750 | configButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
||
23474 | jghali | 751 | |
15552 | fschmid | 752 | configMenue = new QMenu(); |
17985 | jghali | 753 | conf_HideDirs = configMenue->addAction( tr("Hide Directories")); |
15552 | fschmid | 754 | conf_HideDirs->setCheckable(true); |
755 | conf_HideDirs->setChecked(false); |
||
756 | conf_HideImages = configMenue->addAction( tr("Hide Images")); |
||
757 | conf_HideImages->setCheckable(true); |
||
758 | conf_HideImages->setChecked(false); |
||
759 | conf_HideVectors = configMenue->addAction( tr("Hide Vector files")); |
||
760 | conf_HideVectors->setCheckable(true); |
||
761 | conf_HideVectors->setChecked(false); |
||
762 | configMenue->addSeparator(); |
||
17985 | jghali | 763 | conf_OpenMode = configMenue->addAction( tr("Open Directories in a new tab")); |
15552 | fschmid | 764 | conf_OpenMode->setCheckable(true); |
765 | conf_OpenMode->setChecked(false); |
||
766 | configButton->setMenu(configMenue); |
||
767 | configButton->setPopupMode(QToolButton::InstantPopup); |
||
5358 | cbradney | 768 | buttonLayout->addWidget( newButton ); |
15533 | fschmid | 769 | buttonLayout->addWidget( upButton ); |
5358 | cbradney | 770 | buttonLayout->addWidget( importButton ); |
771 | buttonLayout->addWidget( closeButton ); |
||
9818 | fschmid | 772 | QSpacerItem* spacer = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
5358 | cbradney | 773 | buttonLayout->addItem( spacer ); |
15552 | fschmid | 774 | buttonLayout->addWidget( configButton ); |
5358 | cbradney | 775 | BiblioLayout->addLayout( buttonLayout ); |
8295 | fschmid | 776 | |
10564 | fschmid | 777 | Frame3 = new QToolBox( this ); |
4643 | fschmid | 778 | activeBView = new BibView(this); |
8336 | fschmid | 779 | Frame3->addItem(activeBView, tr("Main")); |
15516 | fschmid | 780 | activeBView->visibleName = tr("Main"); |
5760 | fschmid | 781 | tempBView = new BibView(this); |
8336 | fschmid | 782 | Frame3->addItem(tempBView, tr("Copied Items")); |
15516 | fschmid | 783 | tempBView->visibleName = tr("Copied Items"); |
23035 | jghali | 784 | m_tempCount = 0; |
22631 | craig | 785 | actItem = nullptr; |
248 | Franz | 786 | BiblioLayout->addWidget( Frame3 ); |
16579 | fschmid | 787 | setWidget( containerWidget ); |
8336 | fschmid | 788 | |
2191 | cbradney | 789 | languageChange(); |
23060 | craig | 790 | m_prefs = PrefsManager::instance().prefsFile->getContext("Scrapbook"); |
23035 | jghali | 791 | conf_HideDirs->setChecked(m_prefs->getBool("hideDirs", false)); |
792 | conf_HideImages->setChecked(m_prefs->getBool("hideImages", false)); |
||
793 | conf_HideVectors->setChecked(m_prefs->getBool("hideVectors", false)); |
||
794 | conf_OpenMode->setChecked(m_prefs->getBool("openMode", false)); |
||
8336 | fschmid | 795 | |
23474 | jghali | 796 | connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange())); |
797 | |||
23035 | jghali | 798 | connect(newButton, SIGNAL(clicked()), this, SLOT(newLib())); |
15533 | fschmid | 799 | connect(upButton, SIGNAL(clicked()), this, SLOT(goOneDirUp())); |
8336 | fschmid | 800 | connect(importButton, SIGNAL(clicked()), this, SLOT(Import())); |
801 | connect(closeButton, SIGNAL(clicked()), this, SLOT(closeLib())); |
||
802 | connect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
15552 | fschmid | 803 | connect(configMenue, SIGNAL(triggered(QAction *)), this, SLOT(updateView())); |
3 | paul | 804 | } |
2144 | cbradney | 805 | |
4735 | fschmid | 806 | void Biblio::setOpenScrapbooks(QStringList &fileNames) |
807 | { |
||
23035 | jghali | 808 | disconnect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
809 | disconnect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
810 | disconnect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
11554 | fschmid | 811 | disconnect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
11239 | fschmid | 812 | disconnect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
8571 | jghali | 813 | for (int rd = 0; rd < fileNames.count(); ++rd) |
4735 | fschmid | 814 | { |
815 | QString fileName = fileNames[rd]; |
||
19064 | jghali | 816 | if (fileName.isEmpty()) |
817 | continue; |
||
818 | QDir d(fileName); |
||
819 | activeBView = new BibView(this); |
||
820 | QFileInfo fd(fileName); |
||
821 | activeBView->canWrite = fd.isWritable(); |
||
822 | activeBView->setAcceptDrops(activeBView->canWrite); |
||
823 | if (activeBView->canWrite) |
||
824 | Frame3->addItem(activeBView, d.dirName()); |
||
825 | else |
||
23054 | craig | 826 | Frame3->addItem(activeBView, IconManager::instance().loadIcon("16/lock.png"), d.dirName()); |
23035 | jghali | 827 | activeBView->readContents(fileName); |
19064 | jghali | 828 | activeBView->ScFilename = fileName; |
829 | activeBView->visibleName = d.dirName(); |
||
830 | ScCore->fileWatcher->addDir(d.absolutePath(), true); |
||
831 | activeBView->scrollToTop(); |
||
4735 | fschmid | 832 | } |
10564 | fschmid | 833 | activeBView = (BibView*)Frame3->widget(0); |
8336 | fschmid | 834 | Frame3->setCurrentIndex(0); |
15533 | fschmid | 835 | upButton->setEnabled(false); |
15552 | fschmid | 836 | updateView(); |
11239 | fschmid | 837 | connect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
23035 | jghali | 838 | connect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
839 | connect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
840 | connect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
11554 | fschmid | 841 | connect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
4735 | fschmid | 842 | } |
843 | |||
844 | QStringList Biblio::getOpenScrapbooks() |
||
845 | { |
||
846 | QStringList ret; |
||
847 | ret.clear(); |
||
5760 | fschmid | 848 | if (Frame3->count() > 2) // omit the first 2 Tabs since they contain the main and temp scrapbook |
4735 | fschmid | 849 | { |
5760 | fschmid | 850 | for (int a = 2; a < Frame3->count(); a++) |
4735 | fschmid | 851 | { |
10564 | fschmid | 852 | BibView* bv = (BibView*)Frame3->widget(a); |
4735 | fschmid | 853 | ret.append(bv->ScFilename); |
854 | } |
||
855 | } |
||
856 | return ret; |
||
857 | } |
||
858 | |||
15516 | fschmid | 859 | QStringList Biblio::getOpenScrapbooksNames() |
860 | { |
||
861 | QStringList ret; |
||
862 | ret.clear(); |
||
863 | for (int a = 0; a < Frame3->count(); a++) |
||
864 | { |
||
865 | BibView* bv = (BibView*)Frame3->widget(a); |
||
866 | ret.append(bv->visibleName); |
||
867 | } |
||
868 | return ret; |
||
869 | } |
||
870 | |||
22635 | craig | 871 | void Biblio::setScrapbookFileName(const QString& fileName) |
1448 | cbradney | 872 | { |
4643 | fschmid | 873 | activeBView->ScFilename=fileName; |
1448 | cbradney | 874 | } |
875 | |||
23670 | craig | 876 | const QString& Biblio::getScrapbookFileName() |
1448 | cbradney | 877 | { |
4643 | fschmid | 878 | return activeBView->ScFilename; |
1448 | cbradney | 879 | } |
880 | |||
23670 | craig | 881 | int Biblio::objectCount() |
2144 | cbradney | 882 | { |
4643 | fschmid | 883 | return activeBView->objectMap.count(); |
2144 | cbradney | 884 | } |
4693 | fschmid | 885 | |
18888 | craig | 886 | bool Biblio::tempHasContents() |
887 | { |
||
888 | return (!tempBView->objectMap.isEmpty()); |
||
889 | } |
||
890 | |||
22635 | craig | 891 | void Biblio::readOldContents(const QString& fileName, const QString& newName) |
4611 | fschmid | 892 | { |
23035 | jghali | 893 | activeBView->readOldContents(fileName, newName); |
9823 | fschmid | 894 | activeBView->scrollToTop(); |
4611 | fschmid | 895 | } |
896 | |||
22635 | craig | 897 | void Biblio::readContents(const QString& fileName) |
2144 | cbradney | 898 | { |
23035 | jghali | 899 | activeBView->readContents(fileName); |
2144 | cbradney | 900 | } |
901 | |||
22635 | craig | 902 | void Biblio::readTempContents(const QString& fileName) |
5760 | fschmid | 903 | { |
23035 | jghali | 904 | tempBView->readContents(fileName); |
5760 | fschmid | 905 | tempBView->ScFilename = fileName; |
23035 | jghali | 906 | m_tempCount = tempBView->objectMap.count(); |
5760 | fschmid | 907 | } |
908 | |||
8571 | jghali | 909 | void Biblio::installEventFilter(QObject *filterObj) |
2144 | cbradney | 910 | { |
16579 | fschmid | 911 | // ScrPaletteBase::installEventFilter(filterObj); |
4643 | fschmid | 912 | activeBView->installEventFilter(filterObj); |
5760 | fschmid | 913 | tempBView->installEventFilter(filterObj); |
2144 | cbradney | 914 | } |
915 | |||
15552 | fschmid | 916 | void Biblio::updateView() |
917 | { |
||
918 | for (int a = 0; a < Frame3->count(); a++) |
||
919 | { |
||
920 | BibView* bv = (BibView*)Frame3->widget(a); |
||
921 | QMap<QString, BibView::Elem>::Iterator itf; |
||
922 | for (itf = bv->objectMap.begin(); itf != bv->objectMap.end(); ++itf) |
||
923 | { |
||
924 | if (itf.value().isDir) |
||
925 | itf.value().widgetItem->setHidden(conf_HideDirs->isChecked()); |
||
926 | if (itf.value().isRaster) |
||
927 | itf.value().widgetItem->setHidden(conf_HideImages->isChecked()); |
||
928 | if (itf.value().isVector) |
||
929 | itf.value().widgetItem->setHidden(conf_HideVectors->isChecked()); |
||
930 | } |
||
931 | } |
||
23035 | jghali | 932 | m_prefs->set("hideDirs", conf_HideDirs->isChecked()); |
933 | m_prefs->set("hideImages", conf_HideImages->isChecked()); |
||
934 | m_prefs->set("hideVectors", conf_HideVectors->isChecked()); |
||
935 | m_prefs->set("openMode", conf_OpenMode->isChecked()); |
||
15552 | fschmid | 936 | } |
937 | |||
23035 | jghali | 938 | void Biblio::newLib() |
3 | paul | 939 | { |
23060 | craig | 940 | PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs"); |
11269 | fschmid | 941 | QString fileName = QFileDialog::getExistingDirectory(this, tr("Choose a Scrapbook Directory"), dirs->get("scrap_load", ".")); |
19064 | jghali | 942 | if (fileName.isEmpty()) |
943 | return; |
||
944 | |||
945 | for (int a = 0; a < Frame3->count(); a++) |
||
248 | Franz | 946 | { |
19064 | jghali | 947 | BibView* bv = (BibView*)Frame3->widget(a); |
948 | if (fileName == bv->ScFilename) |
||
949 | return; |
||
248 | Franz | 950 | } |
23035 | jghali | 951 | disconnect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
952 | disconnect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
953 | disconnect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
19064 | jghali | 954 | disconnect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
955 | disconnect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
956 | QDir d(fileName); |
||
957 | activeBView = new BibView(this); |
||
958 | QFileInfo fd(fileName); |
||
959 | activeBView->canWrite = fd.isWritable(); |
||
960 | activeBView->setAcceptDrops(activeBView->canWrite); |
||
961 | if (activeBView->canWrite) |
||
962 | Frame3->addItem(activeBView, d.dirName()); |
||
963 | else |
||
23054 | craig | 964 | Frame3->addItem(activeBView, IconManager::instance().loadIcon("16/lock.png"), d.dirName()); |
23035 | jghali | 965 | activeBView->readContents(fileName); |
19064 | jghali | 966 | activeBView->ScFilename = fileName; |
967 | activeBView->visibleName = d.dirName(); |
||
968 | Frame3->setCurrentWidget(activeBView); |
||
969 | ScCore->fileWatcher->addDir(d.absolutePath(), true); |
||
970 | d.cdUp(); |
||
971 | dirs->set("scrap_load", d.absolutePath()); |
||
972 | activeBView->scrollToTop(); |
||
973 | upButton->setEnabled(!((Frame3->currentIndex() == 0) || (Frame3->currentIndex() == 1))); |
||
974 | updateView(); |
||
975 | connect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
23035 | jghali | 976 | connect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
977 | connect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
978 | connect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
22635 | craig | 979 | connect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(handleDoubleClick(QListWidgetItem*))); |
19064 | jghali | 980 | emit scrapbookListChanged(); |
3 | paul | 981 | } |
15533 | fschmid | 982 | |
5058 | tsoots | 983 | void Biblio::Import() |
984 | { |
||
23060 | craig | 985 | PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs"); |
11269 | fschmid | 986 | QString s = QFileDialog::getOpenFileName(this, |
987 | tr("Choose a scrapbook file to import"), |
||
988 | dirs->get("old_scrap_load", "."), |
||
989 | tr("Scrapbook (*.scs *.SCS)")); |
||
5058 | tsoots | 990 | |
991 | if (!s.isEmpty()) |
||
992 | { |
||
16577 | craig | 993 | dirs->set("old_scrap_load", s.left(s.lastIndexOf(QDir::toNativeSeparators("/")))); |
5058 | tsoots | 994 | |
22635 | craig | 995 | QFileInfo scrapbookFileInfoO = QFileInfo(s); |
5058 | tsoots | 996 | if (scrapbookFileInfoO.exists()) |
997 | { |
||
22635 | craig | 998 | readOldContents(s, activeBView->ScFilename); |
5058 | tsoots | 999 | readContents(activeBView->ScFilename); |
1000 | } |
||
9823 | fschmid | 1001 | activeBView->scrollToTop(); |
15552 | fschmid | 1002 | updateView(); |
5058 | tsoots | 1003 | } |
1004 | } |
||
1005 | |||
4643 | fschmid | 1006 | void Biblio::closeLib() |
1007 | { |
||
5760 | fschmid | 1008 | if (Frame3->count() == 2) |
4643 | fschmid | 1009 | close(); |
8336 | fschmid | 1010 | if ((Frame3->currentIndex() == 0) || (Frame3->currentIndex() == 1)) |
5779 | fschmid | 1011 | return; |
19064 | jghali | 1012 | |
23035 | jghali | 1013 | disconnect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
1014 | disconnect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
1015 | disconnect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
19064 | jghali | 1016 | disconnect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
1017 | disconnect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
1018 | QFileInfo fi(activeBView->ScFilename); |
||
1019 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
1020 | Frame3->removeItem(Frame3->indexOf(activeBView)); |
||
1021 | delete activeBView; // currently disabled as the whole TabWidget vanishes when executing that delete????? -> seems to be fixed in Qt-4.3.3 |
||
1022 | activeBView = (BibView*)Frame3->widget(0); |
||
1023 | Frame3->setCurrentIndex(0); |
||
1024 | upButton->setEnabled(!((Frame3->currentIndex() == 0) || (Frame3->currentIndex() == 1))); |
||
1025 | connect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
23035 | jghali | 1026 | connect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
1027 | connect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
1028 | connect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
19064 | jghali | 1029 | connect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
1030 | emit scrapbookListChanged(); |
||
4643 | fschmid | 1031 | } |
1032 | |||
8336 | fschmid | 1033 | void Biblio::libChanged(int index) |
4643 | fschmid | 1034 | { |
23035 | jghali | 1035 | disconnect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
1036 | disconnect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
1037 | disconnect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
11554 | fschmid | 1038 | disconnect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
10564 | fschmid | 1039 | activeBView = (BibView*)Frame3->widget(index); |
15533 | fschmid | 1040 | upButton->setEnabled(!((Frame3->currentIndex() == 0) || (Frame3->currentIndex() == 1))); |
23035 | jghali | 1041 | connect(activeBView, SIGNAL(objDropped(QString)), this, SLOT(objFromMenu(QString))); |
1042 | connect(activeBView, SIGNAL(fileDropped(QString, int)), this, SLOT(objFromFile(QString, int))); |
||
1043 | connect(activeBView, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(handleMouse(QPoint))); |
||
11554 | fschmid | 1044 | connect(activeBView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(handleDoubleClick(QListWidgetItem *))); |
4643 | fschmid | 1045 | } |
3 | paul | 1046 | |
22635 | craig | 1047 | void Biblio::closeOnDel(const QString& libName) |
15527 | fschmid | 1048 | { |
22516 | craig | 1049 | BibView* bv = nullptr; |
15527 | fschmid | 1050 | int libIndex = 0; |
1051 | for (int a = 0; a < Frame3->count(); a++) |
||
1052 | { |
||
1053 | bv = (BibView*)Frame3->widget(a); |
||
1054 | if (libName == bv->ScFilename) |
||
1055 | { |
||
1056 | libIndex = a; |
||
1057 | break; |
||
1058 | } |
||
1059 | } |
||
1060 | if ((libIndex == 0) || (libIndex == 1)) |
||
1061 | return; |
||
1062 | if (bv == activeBView) |
||
1063 | closeLib(); |
||
1064 | else |
||
1065 | { |
||
1066 | disconnect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
1067 | QFileInfo fi(bv->ScFilename); |
||
1068 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
1069 | Frame3->removeItem(Frame3->indexOf(bv)); |
||
1070 | delete bv; |
||
1071 | connect(Frame3, SIGNAL(currentChanged(int)), this, SLOT(libChanged(int ))); |
||
1072 | } |
||
1073 | } |
||
1074 | |||
22635 | craig | 1075 | void Biblio::reloadLib(const QString& fileName) |
15526 | fschmid | 1076 | { |
1077 | for (int a = 0; a < Frame3->count(); a++) |
||
1078 | { |
||
1079 | BibView* bv = (BibView*)Frame3->widget(a); |
||
1080 | if (bv->ScFilename == fileName) |
||
1081 | { |
||
23035 | jghali | 1082 | bv->readContents(fileName); |
15526 | fschmid | 1083 | bv->ScFilename = fileName; |
1084 | QDir d(fileName); |
||
18075 | fschmid | 1085 | if (a > 1) |
1086 | bv->visibleName = d.dirName(); |
||
15526 | fschmid | 1087 | bv->scrollToTop(); |
1088 | } |
||
1089 | } |
||
15552 | fschmid | 1090 | updateView(); |
15526 | fschmid | 1091 | } |
1092 | |||
11554 | fschmid | 1093 | void Biblio::handleDoubleClick(QListWidgetItem *ite) |
1094 | { |
||
15533 | fschmid | 1095 | if (activeBView->objectMap[ite->text()].isDir) |
1096 | { |
||
1097 | QFileInfo fi(activeBView->ScFilename); |
||
1098 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
1099 | QString fileName = activeBView->ScFilename + "/" + ite->text(); |
||
1100 | QDir d(fileName); |
||
1101 | QFileInfo fd(fileName); |
||
15552 | fschmid | 1102 | if (conf_OpenMode->isChecked()) |
1103 | { |
||
1104 | activeBView = new BibView(this); |
||
1105 | if (fd.isWritable()) |
||
1106 | Frame3->addItem(activeBView, d.dirName()); |
||
1107 | else |
||
23054 | craig | 1108 | Frame3->addItem(activeBView, IconManager::instance().loadIcon("16/lock.png"), d.dirName()); |
15552 | fschmid | 1109 | } |
15533 | fschmid | 1110 | activeBView->canWrite = fd.isWritable(); |
1111 | activeBView->setAcceptDrops(activeBView->canWrite); |
||
23035 | jghali | 1112 | activeBView->readContents(fileName); |
15533 | fschmid | 1113 | activeBView->ScFilename = fileName; |
1114 | activeBView->visibleName = d.dirName(); |
||
1115 | Frame3->setItemText(Frame3->indexOf(activeBView), d.dirName()); |
||
1116 | if (!activeBView->canWrite) |
||
23054 | craig | 1117 | Frame3->setItemIcon(Frame3->indexOf(activeBView), IconManager::instance().loadIcon("16/lock.png")); |
15533 | fschmid | 1118 | ScCore->fileWatcher->addDir(d.absolutePath(), true); |
1119 | d.cdUp(); |
||
23060 | craig | 1120 | PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs"); |
15533 | fschmid | 1121 | dirs->set("scrap_load", d.absolutePath()); |
1122 | activeBView->scrollToTop(); |
||
15552 | fschmid | 1123 | updateView(); |
15533 | fschmid | 1124 | } |
1125 | else |
||
1126 | { |
||
1127 | emit pasteToActualPage(ite->text()); |
||
1128 | activeBView->clearSelection(); |
||
22631 | craig | 1129 | actItem = nullptr; |
15533 | fschmid | 1130 | } |
11554 | fschmid | 1131 | } |
1132 | |||
15533 | fschmid | 1133 | void Biblio::goOneDirUp() |
1134 | { |
||
1135 | QFileInfo fi(activeBView->ScFilename); |
||
1136 | ScCore->fileWatcher->removeDir(fi.absolutePath()); |
||
1137 | QDir d(activeBView->ScFilename); |
||
1138 | d.cdUp(); |
||
1139 | QString fileName = d.absolutePath(); |
||
1140 | QFileInfo fd(fileName); |
||
1141 | activeBView->canWrite = fd.isWritable(); |
||
1142 | activeBView->setAcceptDrops(activeBView->canWrite); |
||
23035 | jghali | 1143 | activeBView->readContents(fileName); |
15533 | fschmid | 1144 | activeBView->ScFilename = fileName; |
1145 | activeBView->visibleName = d.dirName(); |
||
1146 | Frame3->setItemText(Frame3->indexOf(activeBView), d.dirName()); |
||
1147 | if (!activeBView->canWrite) |
||
23054 | craig | 1148 | Frame3->setItemIcon(Frame3->indexOf(activeBView), IconManager::instance().loadIcon("16/lock.png")); |
15533 | fschmid | 1149 | ScCore->fileWatcher->addDir(d.absolutePath(), true); |
1150 | d.cdUp(); |
||
23060 | craig | 1151 | PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs"); |
15533 | fschmid | 1152 | dirs->set("scrap_load", d.absolutePath()); |
1153 | activeBView->scrollToTop(); |
||
15552 | fschmid | 1154 | updateView(); |
15533 | fschmid | 1155 | } |
1156 | |||
11557 | fschmid | 1157 | void Biblio::handlePasteToPage() |
1158 | { |
||
1159 | emit pasteToActualPage(actItem->text()); |
||
1160 | activeBView->clearSelection(); |
||
22631 | craig | 1161 | actItem = nullptr; |
11557 | fschmid | 1162 | } |
1163 | |||
23035 | jghali | 1164 | void Biblio::handleMouse(QPoint p) |
3 | paul | 1165 | { |
19203 | jghali | 1166 | // #12359 : stop the file watcher here as it may run and trigger regeneration of |
1167 | // scrapbook content, hence invalidating actItem while context menu is executing. |
||
1168 | ScCore->fileWatcher->stop(); |
||
9819 | fschmid | 1169 | QListWidgetItem *ite = activeBView->itemAt(p); |
22631 | craig | 1170 | if (ite != nullptr) |
248 | Franz | 1171 | { |
9819 | fschmid | 1172 | actItem = ite; |
9818 | fschmid | 1173 | QMenu *pmenu = new QMenu(); |
9819 | fschmid | 1174 | QAction* renAct; |
1175 | QAction* delAct; |
||
11557 | fschmid | 1176 | QAction* pasteAct = pmenu->addAction( tr("Paste to Page")); |
1177 | connect(pasteAct, SIGNAL(triggered()), this, SLOT(handlePasteToPage())); |
||
9819 | fschmid | 1178 | if (activeBView->canWrite) |
1179 | { |
||
1180 | renAct = pmenu->addAction( tr("Rename")); |
||
1181 | connect(renAct, SIGNAL(triggered()), this, SLOT(renameObj())); |
||
1182 | delAct = pmenu->addAction( tr("Delete")); |
||
1183 | connect(delAct, SIGNAL(triggered()), this, SLOT(deleteObj())); |
||
1184 | } |
||
9818 | fschmid | 1185 | QSignalMapper *signalMapper = new QSignalMapper(this); |
1186 | connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(copyObj(int))); |
||
1187 | QMenu *pmenu2 = new QMenu( tr("Copy To:")); |
||
9945 | fschmid | 1188 | QMenu *pmenu3 = new QMenu( tr("Move To:")); |
1189 | QSignalMapper *signalMapper2 = new QSignalMapper(this); |
||
1190 | connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(moveObj(int))); |
||
5806 | fschmid | 1191 | for (int a = 0; a < Frame3->count(); a++) |
1192 | { |
||
10564 | fschmid | 1193 | BibView* bv = (BibView*)Frame3->widget(a); |
19203 | jghali | 1194 | if ((bv == activeBView) || (!bv->canWrite)) |
1195 | continue; |
||
1196 | QAction *action = pmenu2->addAction(Frame3->itemText(Frame3->indexOf(Frame3->widget(a)))); |
||
1197 | connect(action, SIGNAL(triggered()), signalMapper, SLOT(map())); |
||
1198 | signalMapper->setMapping(action, a); |
||
1199 | if (activeBView->canWrite) |
||
5806 | fschmid | 1200 | { |
19203 | jghali | 1201 | QAction *action2 = pmenu3->addAction(Frame3->itemText(Frame3->indexOf(Frame3->widget(a)))); |
1202 | connect(action2, SIGNAL(triggered()), signalMapper2, SLOT(map())); |
||
1203 | signalMapper2->setMapping(action2, a); |
||
5806 | fschmid | 1204 | } |
1205 | } |
||
9818 | fschmid | 1206 | pmenu->addMenu(pmenu2); |
9819 | fschmid | 1207 | if (activeBView->canWrite) |
1208 | pmenu->addMenu(pmenu3); |
||
9818 | fschmid | 1209 | pmenu->exec(QCursor::pos()); |
248 | Franz | 1210 | delete pmenu; |
9818 | fschmid | 1211 | delete pmenu2; |
1212 | delete signalMapper; |
||
9819 | fschmid | 1213 | if (activeBView->canWrite) |
1214 | { |
||
1215 | delete pmenu3; |
||
1216 | delete signalMapper2; |
||
1217 | } |
||
248 | Franz | 1218 | } |
11239 | fschmid | 1219 | else |
1220 | { |
||
1221 | QMenu *pmenu = new QMenu(); |
||
18075 | fschmid | 1222 | QAction* closeAct = pmenu->addAction( tr("Close")); |
11239 | fschmid | 1223 | if ((activeBView->canWrite) && (activeBView->objectMap.count() != 0)) |
1224 | { |
||
18075 | fschmid | 1225 | QAction* delAct = pmenu->addAction( tr("Delete Contents")); |
11239 | fschmid | 1226 | connect(delAct, SIGNAL(triggered()), this, SLOT(deleteAllObj())); |
1227 | } |
||
1228 | connect(closeAct, SIGNAL(triggered()), this, SLOT(closeLib())); |
||
1229 | pmenu->exec(QCursor::pos()); |
||
1230 | delete pmenu; |
||
1231 | } |
||
5806 | fschmid | 1232 | activeBView->clearSelection(); |
22631 | craig | 1233 | actItem = nullptr; |
19203 | jghali | 1234 | ScCore->fileWatcher->start(); |
3 | paul | 1235 | } |
1236 | |||
5806 | fschmid | 1237 | bool Biblio::copyObj(int id) |
1238 | { |
||
9819 | fschmid | 1239 | QListWidgetItem *ite = actItem; |
5806 | fschmid | 1240 | QString nam = ite->text(); |
10564 | fschmid | 1241 | BibView* bv = (BibView*)Frame3->widget(id); |
5806 | fschmid | 1242 | if (bv->objectMap.contains(nam)) |
1243 | { |
||
18194 | fschmid | 1244 | Query dia(this, "tt", 1, tr("&Name:"), tr("New Entry")); |
17895 | fschmid | 1245 | dia.setValidator(QRegExp("[\\w()]+")); |
17235 | craig | 1246 | dia.setEditText(nam, true); |
1247 | dia.setTestList(activeBView->objectMap.keys()); |
||
1248 | if (dia.exec()) |
||
1249 | nam = dia.getEditText(); |
||
5806 | fschmid | 1250 | else |
1251 | return false; |
||
1252 | } |
||
1253 | QPixmap pm; |
||
9535 | fschmid | 1254 | QByteArray cf; |
10398 | cbradney | 1255 | if (!loadRawText(QDir::cleanPath(activeBView->objectMap[ite->text()].Data), cf)) |
5806 | fschmid | 1256 | return false; |
1257 | pm = activeBView->objectMap[ite->text()].Preview; |
||
6028 | jghali | 1258 | QString dt = activeBView->objectMap[ite->text()].Data; |
15520 | fschmid | 1259 | QDir thumbs(bv->ScFilename); |
1260 | if (thumbs.exists()) |
||
1261 | { |
||
23060 | craig | 1262 | if ((bv->canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
15520 | fschmid | 1263 | thumbs.mkdir(".ScribusThumbs"); |
1264 | } |
||
5806 | fschmid | 1265 | QFileInfo fi(dt); |
16577 | craig | 1266 | QFile f(QDir::cleanPath(QDir::toNativeSeparators(bv->ScFilename + "/" + nam + "." + fi.completeSuffix().toLower()))); |
22708 | jghali | 1267 | if (!f.open(QIODevice::WriteOnly)) |
5806 | fschmid | 1268 | return false; |
9818 | fschmid | 1269 | QDataStream s; |
5806 | fschmid | 1270 | s.setDevice(&f); |
10564 | fschmid | 1271 | s.writeRawData(cf.data(), cf.length()); |
5806 | fschmid | 1272 | f.close(); |
23035 | jghali | 1273 | bv->addObject(nam, QDir::cleanPath(QDir::toNativeSeparators(bv->ScFilename + "/" + nam + "." + fi.completeSuffix().toLower())), pm); |
16577 | craig | 1274 | pm.save(QDir::cleanPath(QDir::toNativeSeparators(bv->ScFilename + "/.ScribusThumbs/" + nam +".png")), "PNG"); |
1275 | QFileInfo fiD(QDir::toNativeSeparators(activeBView->ScFilename + "/" + fi.baseName())); |
||
8295 | fschmid | 1276 | if ((fiD.exists()) && (fiD.isDir())) |
1277 | { |
||
16577 | craig | 1278 | QDir dd = QDir(QDir::cleanPath(QDir::toNativeSeparators(bv->ScFilename))); |
1279 | dd.mkdir(QDir::cleanPath(QDir::toNativeSeparators(bv->ScFilename + "/" + nam))); |
||
1280 | QDir d(QDir::toNativeSeparators(activeBView->ScFilename + "/" + fi.baseName()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
||
8295 | fschmid | 1281 | if ((d.exists()) && (d.count() != 0)) |
1282 | { |
||
1283 | for (uint dc = 0; dc < d.count(); ++dc) |
||
1284 | { |
||
16577 | craig | 1285 | QString source = QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + fi.baseName() + "/" + d[dc])); |
1286 | QString target = QDir::cleanPath(QDir::toNativeSeparators(bv->ScFilename + "/" + nam + "/" + d[dc])); |
||
8295 | fschmid | 1287 | copyFile(source, target); |
1288 | } |
||
1289 | } |
||
1290 | if (fiD.baseName() != nam) |
||
16577 | craig | 1291 | adjustReferences(QDir::toNativeSeparators(bv->ScFilename + "/" + nam + "." + fi.completeSuffix().toLower())); |
8295 | fschmid | 1292 | } |
14763 | cbradney | 1293 | pm = pm.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
9819 | fschmid | 1294 | QPixmap pm2(60, 60); |
10737 | fschmid | 1295 | pm2.fill(palette().color(QPalette::Base)); |
9819 | fschmid | 1296 | QPainter p; |
1297 | p.begin(&pm2); |
||
1298 | p.drawPixmap(30 - pm.width() / 2, 30 - pm.height() / 2, pm); |
||
1299 | p.end(); |
||
15552 | fschmid | 1300 | QListWidgetItem *item = new QListWidgetItem(QIcon(pm), nam, bv); |
21181 | fschmid | 1301 | item->setToolTip(nam); |
15552 | fschmid | 1302 | bv->objectMap[nam].widgetItem = item; |
5806 | fschmid | 1303 | if (bv == tempBView) |
1304 | { |
||
23035 | jghali | 1305 | m_tempCount++; |
23060 | craig | 1306 | if (tempBView->objectMap.count() > PrefsManager::instance().appPrefs.scrapbookPrefs.numScrapbookCopies) |
5806 | fschmid | 1307 | { |
1308 | QMap<QString,BibView::Elem>::Iterator it; |
||
1309 | it = tempBView->objectMap.begin(); |
||
10516 | cbradney | 1310 | QFile f(it.value().Data); |
5806 | fschmid | 1311 | f.remove(); |
16577 | craig | 1312 | QFileInfo fi(QDir::toNativeSeparators(tempBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
5806 | fschmid | 1313 | if (fi.exists()) |
1314 | { |
||
16577 | craig | 1315 | QFile f2(QDir::toNativeSeparators(tempBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
5806 | fschmid | 1316 | f2.remove(); |
1317 | } |
||
16577 | craig | 1318 | QFileInfo fiD(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key())); |
8295 | fschmid | 1319 | if ((fiD.exists()) && (fiD.isDir())) |
1320 | { |
||
16577 | craig | 1321 | QDir dd = QDir(QDir::toNativeSeparators(tempBView->ScFilename)); |
1322 | QDir d(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
||
8295 | fschmid | 1323 | if ((d.exists()) && (d.count() != 0)) |
1324 | { |
||
1325 | for (uint dc = 0; dc < d.count(); ++dc) |
||
1326 | { |
||
16577 | craig | 1327 | QFile::remove(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key() + "/" + d[dc])); |
8295 | fschmid | 1328 | } |
1329 | } |
||
16577 | craig | 1330 | dd.rmdir(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key())); |
8295 | fschmid | 1331 | } |
9818 | fschmid | 1332 | QString name = it.key(); |
10564 | fschmid | 1333 | tempBView->objectMap.erase(it); |
9818 | fschmid | 1334 | QList<QListWidgetItem *> itL = tempBView->findItems(name, Qt::MatchExactly); |
1335 | if (itL.count() > 0) |
||
1336 | { |
||
1337 | ite = itL.at(0); |
||
1338 | delete tempBView->takeItem(tempBView->row(ite)); |
||
1339 | } |
||
5806 | fschmid | 1340 | } |
1341 | emit updateRecentMenue(); |
||
1342 | } |
||
1343 | return true; |
||
1344 | } |
||
1345 | |||
1346 | void Biblio::moveObj(int id) |
||
1347 | { |
||
1348 | if (copyObj(id)) |
||
1349 | { |
||
9818 | fschmid | 1350 | deleteObj(); |
5806 | fschmid | 1351 | } |
1352 | } |
||
1353 | |||
9818 | fschmid | 1354 | void Biblio::deleteObj() |
3 | paul | 1355 | { |
9819 | fschmid | 1356 | if (!activeBView->canWrite) |
1357 | return; |
||
1358 | QListWidgetItem *ite = actItem; |
||
9818 | fschmid | 1359 | QString name = ite->text(); |
8295 | fschmid | 1360 | QFile::remove(activeBView->objectMap[name].Data); |
16577 | craig | 1361 | QFileInfo fi(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + name + ".png")); |
4649 | fschmid | 1362 | if (fi.exists()) |
16577 | craig | 1363 | QFile::remove(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + name + ".png")); |
1364 | QFileInfo fiD(QDir::toNativeSeparators(activeBView->ScFilename + "/" + name)); |
||
8295 | fschmid | 1365 | if ((fiD.exists()) && (fiD.isDir())) |
4649 | fschmid | 1366 | { |
16577 | craig | 1367 | QDir dd = QDir(QDir::toNativeSeparators(activeBView->ScFilename)); |
1368 | QDir d(QDir::toNativeSeparators(activeBView->ScFilename + "/" + name), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
||
8295 | fschmid | 1369 | if ((d.exists()) && (d.count() != 0)) |
1370 | { |
||
1371 | for (uint dc = 0; dc < d.count(); ++dc) |
||
1372 | { |
||
16577 | craig | 1373 | QFile::remove(QDir::toNativeSeparators(activeBView->ScFilename + "/" + name + "/" + d[dc])); |
8295 | fschmid | 1374 | } |
1375 | } |
||
1376 | dd.rmdir(name); |
||
4649 | fschmid | 1377 | } |
4643 | fschmid | 1378 | activeBView->objectMap.remove(name); |
9818 | fschmid | 1379 | delete activeBView->takeItem(activeBView->row(ite)); |
5806 | fschmid | 1380 | if (activeBView == tempBView) |
1381 | emit updateRecentMenue(); |
||
22631 | craig | 1382 | actItem = nullptr; |
3 | paul | 1383 | } |
1384 | |||
11239 | fschmid | 1385 | void Biblio::deleteAllObj() |
1386 | { |
||
1387 | if (!activeBView->canWrite) |
||
1388 | return; |
||
19605 | jghali | 1389 | int t = ScMessageBox::warning(this, CommonStrings::trWarning, tr("Do you really want to delete all entries?"), |
1390 | QMessageBox::Yes | QMessageBox::No, |
||
1391 | QMessageBox::No, // GUI default |
||
1392 | QMessageBox::Yes); // batch default |
||
11239 | fschmid | 1393 | if (t == QMessageBox::No) |
1394 | return; |
||
1395 | QMap<QString,BibView::Elem>::Iterator it; |
||
1396 | for (it = activeBView->objectMap.begin(); it != activeBView->objectMap.end(); ++it) |
||
1397 | { |
||
1398 | QFile f(it.value().Data); |
||
1399 | f.remove(); |
||
16577 | craig | 1400 | QFileInfo fi(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
11239 | fschmid | 1401 | if (fi.exists()) |
1402 | { |
||
16577 | craig | 1403 | QFile f2(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
11239 | fschmid | 1404 | f2.remove(); |
1405 | } |
||
16577 | craig | 1406 | QFileInfo fiD(QDir::toNativeSeparators(activeBView->ScFilename + "/" + it.key())); |
11239 | fschmid | 1407 | if ((fiD.exists()) && (fiD.isDir())) |
1408 | { |
||
16577 | craig | 1409 | QDir dd = QDir(QDir::toNativeSeparators(activeBView->ScFilename)); |
1410 | QDir d(QDir::toNativeSeparators(activeBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
||
11239 | fschmid | 1411 | if ((d.exists()) && (d.count() != 0)) |
1412 | { |
||
1413 | for (uint dc = 0; dc < d.count(); ++dc) |
||
1414 | { |
||
16577 | craig | 1415 | QFile::remove(QDir::toNativeSeparators(activeBView->ScFilename + "/" + it.key() + "/" + d[dc])); |
11239 | fschmid | 1416 | } |
1417 | } |
||
16577 | craig | 1418 | dd.rmdir(QDir::toNativeSeparators(activeBView->ScFilename + "/" + it.key())); |
11239 | fschmid | 1419 | } |
1420 | } |
||
1421 | activeBView->clear(); |
||
1422 | activeBView->objectMap.clear(); |
||
1423 | if (activeBView == tempBView) |
||
1424 | emit updateRecentMenue(); |
||
22631 | craig | 1425 | actItem = nullptr; |
11239 | fschmid | 1426 | } |
1427 | |||
9819 | fschmid | 1428 | void Biblio::renameObj() |
291 | Franz | 1429 | { |
9819 | fschmid | 1430 | if (!activeBView->canWrite) |
1431 | return; |
||
1432 | QString nam; |
||
23035 | jghali | 1433 | QString objData; |
1434 | QPixmap objPreview; |
||
9819 | fschmid | 1435 | QListWidgetItem *ite = actItem; |
23035 | jghali | 1436 | QString oldName = ite->text(); |
18194 | fschmid | 1437 | Query dia(this, "tt", 1, tr("&Name:"), tr("New Name")); |
17895 | fschmid | 1438 | dia.setValidator(QRegExp("[\\w()]+")); |
17235 | craig | 1439 | dia.setEditText(ite->text(), true); |
1440 | dia.setTestList(activeBView->objectMap.keys()); |
||
1441 | if (dia.exec()) |
||
1442 | nam = dia.getEditText(); |
||
9819 | fschmid | 1443 | else |
1444 | return; |
||
1445 | ite->setText(nam); |
||
21181 | fschmid | 1446 | ite->setToolTip(nam); |
23035 | jghali | 1447 | objData = activeBView->objectMap[oldName].Data; |
1448 | objPreview = activeBView->objectMap[oldName].Preview; |
||
9819 | fschmid | 1449 | QDir d = QDir(); |
23035 | jghali | 1450 | d.rename(objData, QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + ite->text() + ".sce"))); |
1451 | QFileInfo fi(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + oldName + ".png")); |
||
9819 | fschmid | 1452 | if (fi.exists()) |
23035 | jghali | 1453 | d.rename(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + oldName + ".png"), QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + ite->text() + ".png"))); |
1454 | QFileInfo fiD(QDir::toNativeSeparators(activeBView->ScFilename + "/" + oldName)); |
||
9819 | fschmid | 1455 | if ((fiD.exists()) && (fiD.isDir())) |
1456 | { |
||
1457 | QDir d = QDir(); |
||
23035 | jghali | 1458 | d.rename(QDir::toNativeSeparators(activeBView->ScFilename + "/" + oldName), QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + ite->text()))); |
16577 | craig | 1459 | adjustReferences(QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + ite->text() + ".sce"))); |
9819 | fschmid | 1460 | } |
23035 | jghali | 1461 | activeBView->objectMap.remove(oldName); |
1462 | activeBView->addObject(ite->text(), QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + ite->text() + ".sce")), objPreview); |
||
9819 | fschmid | 1463 | if (activeBView == tempBView) |
1464 | emit updateRecentMenue(); |
||
291 | Franz | 1465 | } |
1466 | |||
22635 | craig | 1467 | void Biblio::adjustReferences(const QString& nam) |
8295 | fschmid | 1468 | { |
9535 | fschmid | 1469 | QByteArray cf; |
8295 | fschmid | 1470 | if (loadRawText(nam, cf)) |
1471 | { |
||
1472 | QString f; |
||
1473 | if (cf.left(16) == "<SCRIBUSELEMUTF8") |
||
1474 | f = QString::fromUtf8(cf.data()); |
||
1475 | else |
||
22635 | craig | 1476 | f = cf.data(); |
8295 | fschmid | 1477 | QDomDocument docu("scridoc"); |
1478 | docu.setContent(f); |
||
1479 | QDomElement elem = docu.documentElement(); |
||
22708 | jghali | 1480 | QDomNode node = elem.firstChild(); |
8295 | fschmid | 1481 | QFileInfo fid(nam); |
22708 | jghali | 1482 | while (!node.isNull()) |
8295 | fschmid | 1483 | { |
22708 | jghali | 1484 | QDomElement pg = node.toElement(); |
1485 | if (pg.tagName() == "ITEM") |
||
8295 | fschmid | 1486 | { |
1487 | PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt()); |
||
1488 | if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame)) |
||
1489 | { |
||
1490 | QString Pfile = pg.attribute("PFILE"); |
||
1491 | if (!Pfile.isEmpty()) |
||
1492 | { |
||
1493 | QFileInfo fi(Pfile); |
||
1494 | pg.setAttribute("PFILE", fid.baseName() + "/" + fi.fileName()); |
||
1495 | } |
||
1496 | QString Pfile2 = pg.attribute("PFILE2",""); |
||
1497 | if (!Pfile2.isEmpty()) |
||
1498 | { |
||
1499 | QFileInfo fi(Pfile2); |
||
1500 | pg.setAttribute("PFILE2", fid.baseName() + "/" + fi.fileName()); |
||
1501 | } |
||
1502 | QString Pfile3 = pg.attribute("PFILE3",""); |
||
1503 | if (!Pfile3.isEmpty()) |
||
1504 | { |
||
1505 | QFileInfo fi(Pfile3); |
||
1506 | pg.setAttribute("PFILE3", fid.baseName() + "/" + fi.fileName()); |
||
1507 | } |
||
1508 | pg.setAttribute("relativePaths", 1); |
||
1509 | } |
||
18483 | fschmid | 1510 | else if (PType == PageItem::OSGFrame) |
1511 | { |
||
1512 | QString Pfile = pg.attribute("modelFile"); |
||
1513 | if (!Pfile.isEmpty()) |
||
1514 | { |
||
1515 | QFileInfo fi(Pfile); |
||
1516 | pg.setAttribute("modelFile", fid.baseName() + "/" + fi.fileName()); |
||
1517 | } |
||
1518 | } |
||
1519 | else if (PType == PageItem::Group) |
||
1520 | { |
||
1521 | adjustReferencesGroups(pg, fid); |
||
1522 | } |
||
8295 | fschmid | 1523 | } |
22708 | jghali | 1524 | node = node.nextSibling(); |
8295 | fschmid | 1525 | } |
1526 | QFile fl(nam); |
||
22708 | jghali | 1527 | if (!fl.open(QIODevice::WriteOnly)) |
8295 | fschmid | 1528 | return ; |
9818 | fschmid | 1529 | QDataStream s; |
8571 | jghali | 1530 | QByteArray cs = docu.toByteArray(); |
8295 | fschmid | 1531 | s.setDevice(&fl); |
10564 | fschmid | 1532 | s.writeRawData(cs.data(), cs.length()); |
8295 | fschmid | 1533 | fl.close(); |
1534 | } |
||
1535 | } |
||
1536 | |||
22635 | craig | 1537 | void Biblio::adjustReferencesGroups(const QDomElement& elem, const QFileInfo& fid) |
18483 | fschmid | 1538 | { |
22708 | jghali | 1539 | QDomNode node = elem.firstChild(); |
1540 | while (!node.isNull()) |
||
18483 | fschmid | 1541 | { |
22708 | jghali | 1542 | QDomElement pg = node.toElement(); |
1543 | if (pg.tagName() == "PAGEOBJECT") |
||
18483 | fschmid | 1544 | { |
1545 | PageItem::ItemType PType = static_cast<PageItem::ItemType>(pg.attribute("PTYPE").toInt()); |
||
1546 | if ((PType == PageItem::ImageFrame) || (PType == PageItem::TextFrame)) |
||
1547 | { |
||
1548 | QString Pfile = pg.attribute("PFILE"); |
||
1549 | if (!Pfile.isEmpty()) |
||
1550 | { |
||
1551 | QFileInfo fi(Pfile); |
||
1552 | pg.setAttribute("PFILE", fid.baseName() + "/" + fi.fileName()); |
||
1553 | } |
||
1554 | QString Pfile2 = pg.attribute("PFILE2",""); |
||
1555 | if (!Pfile2.isEmpty()) |
||
1556 | { |
||
1557 | QFileInfo fi(Pfile2); |
||
1558 | pg.setAttribute("PFILE2", fid.baseName() + "/" + fi.fileName()); |
||
1559 | } |
||
1560 | QString Pfile3 = pg.attribute("PFILE3",""); |
||
1561 | if (!Pfile3.isEmpty()) |
||
1562 | { |
||
1563 | QFileInfo fi(Pfile3); |
||
1564 | pg.setAttribute("PFILE3", fid.baseName() + "/" + fi.fileName()); |
||
1565 | } |
||
1566 | pg.setAttribute("relativePaths", 1); |
||
1567 | } |
||
1568 | else if (PType == PageItem::OSGFrame) |
||
1569 | { |
||
1570 | QString Pfile = pg.attribute("modelFile"); |
||
1571 | if (!Pfile.isEmpty()) |
||
1572 | { |
||
1573 | QFileInfo fi(Pfile); |
||
1574 | pg.setAttribute("modelFile", fid.baseName() + "/" + fi.fileName()); |
||
1575 | } |
||
1576 | } |
||
1577 | else if (PType == PageItem::Group) |
||
1578 | { |
||
1579 | adjustReferencesGroups(pg, fid); |
||
1580 | } |
||
1581 | } |
||
22708 | jghali | 1582 | node = node.nextSibling(); |
18483 | fschmid | 1583 | } |
1584 | } |
||
1585 | |||
11548 | fschmid | 1586 | QString Biblio::getObjectName(QString &text) |
1587 | { |
||
1588 | QDomDocument docu("scridoc"); |
||
1589 | docu.setContent(text); |
||
1590 | QDomElement elem = docu.documentElement(); |
||
22708 | jghali | 1591 | QDomNode node = elem.firstChild(); |
11548 | fschmid | 1592 | QString result = ""; |
22708 | jghali | 1593 | while (!node.isNull()) |
11548 | fschmid | 1594 | { |
22708 | jghali | 1595 | QDomElement pg = node.toElement(); |
1596 | if (pg.tagName() == "ITEM") |
||
11548 | fschmid | 1597 | { |
1598 | result = pg.attribute("ANNAME"); |
||
1599 | break; |
||
1600 | } |
||
22708 | jghali | 1601 | node = node.nextSibling(); |
11548 | fschmid | 1602 | } |
1603 | return result; |
||
1604 | } |
||
1605 | |||
23035 | jghali | 1606 | void Biblio::objFromFile(const QString& path, int testResult) |
14715 | fschmid | 1607 | { |
1608 | if (!activeBView->canWrite) |
||
1609 | return; |
||
15552 | fschmid | 1610 | bool isImage = false; |
1611 | bool isVector = false; |
||
14715 | fschmid | 1612 | QString tmp; |
1613 | QFileInfo fi(path); |
||
22708 | jghali | 1614 | if (!fi.exists()) |
1615 | return; |
||
1616 | |||
1617 | QString nam = fi.baseName(); |
||
1618 | if (Frame3->currentIndex() == 1) |
||
14715 | fschmid | 1619 | { |
22708 | jghali | 1620 | if (activeBView->objectMap.contains(nam)) |
23035 | jghali | 1621 | nam += "("+ tmp.setNum(m_tempCount) + ")"; |
1622 | m_tempCount++; |
||
22708 | jghali | 1623 | } |
1624 | else |
||
1625 | { |
||
1626 | if (activeBView->objectMap.contains(nam)) |
||
23035 | jghali | 1627 | nam += "("+ tmp.setNum(m_tempCount) + ")"; |
22708 | jghali | 1628 | } |
1629 | Query dia(this, "tt", true, tr("&Name:"), tr("New Entry")); |
||
1630 | dia.setValidator(QRegExp("[\\w()]+")); |
||
1631 | dia.setEditText(nam, true); |
||
1632 | dia.setTestList(activeBView->objectMap.keys()); |
||
1633 | if (dia.exec()) |
||
1634 | nam = dia.getEditText(); |
||
1635 | else |
||
1636 | return; |
||
1637 | QImage img; |
||
1638 | if (testResult == 9999) |
||
1639 | { |
||
1640 | bool mode = false; |
||
1641 | ScImage im; |
||
1642 | CMSettings cms(nullptr, "", Intent_Perceptual); |
||
1643 | cms.allowColorManagement(false); |
||
1644 | if (im.loadPicture(path, 1, cms, ScImage::Thumbnail, 72, &mode)) |
||
1645 | img = im.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
||
1646 | isImage = true; |
||
1647 | } |
||
1648 | else |
||
1649 | { |
||
1650 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
||
1651 | if (fmt) |
||
14715 | fschmid | 1652 | { |
22708 | jghali | 1653 | img = fmt->readThumbnail(path); |
1654 | img = img.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
||
14715 | fschmid | 1655 | } |
22708 | jghali | 1656 | isVector = true; |
1657 | } |
||
1658 | QByteArray cf; |
||
1659 | if (!loadRawText(path, cf)) |
||
1660 | return; |
||
1661 | QPixmap pm = QPixmap::fromImage(img); |
||
1662 | QFile f(QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + nam + "." + fi.completeSuffix()))); |
||
1663 | if (!f.open(QIODevice::WriteOnly)) |
||
1664 | return; |
||
1665 | QDataStream s; |
||
1666 | s.setDevice(&f); |
||
1667 | s.writeRawData(cf.data(), cf.length()); |
||
1668 | f.close(); |
||
23060 | craig | 1669 | if (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews) |
22708 | jghali | 1670 | { |
1671 | QDir thumbs(activeBView->ScFilename); |
||
1672 | if (thumbs.exists()) |
||
14715 | fschmid | 1673 | { |
23060 | craig | 1674 | if ((activeBView->canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
22708 | jghali | 1675 | thumbs.mkdir(".ScribusThumbs"); |
14715 | fschmid | 1676 | } |
22708 | jghali | 1677 | img.save(QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + nam +".png")), "PNG"); |
1678 | } |
||
23035 | jghali | 1679 | activeBView->addObject(nam, QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + nam + "." + fi.completeSuffix())), pm, false, isImage, isVector); |
22708 | jghali | 1680 | QPixmap pm2(60, 60); |
1681 | pm2.fill(palette().color(QPalette::Base)); |
||
1682 | QPainter p; |
||
1683 | p.begin(&pm2); |
||
1684 | p.drawPixmap(30 - pm.width() / 2, 30 - pm.height() / 2, pm); |
||
1685 | p.end(); |
||
1686 | QListWidgetItem *item = new QListWidgetItem(QIcon(pm2), nam, activeBView); |
||
1687 | item->setToolTip(nam); |
||
1688 | activeBView->objectMap[nam].widgetItem = item; |
||
1689 | if (isImage) |
||
1690 | item->setHidden(conf_HideImages->isChecked()); |
||
1691 | if (isVector) |
||
1692 | item->setHidden(conf_HideVectors->isChecked()); |
||
1693 | if (Frame3->currentIndex() == 1) |
||
1694 | { |
||
23060 | craig | 1695 | if (tempBView->objectMap.count() > PrefsManager::instance().appPrefs.scrapbookPrefs.numScrapbookCopies) |
14715 | fschmid | 1696 | { |
22708 | jghali | 1697 | QMap<QString,BibView::Elem>::Iterator it; |
1698 | it = tempBView->objectMap.begin(); |
||
1699 | QFile f(it.value().Data); |
||
1700 | f.remove(); |
||
1701 | QFileInfo fi(QDir::toNativeSeparators(tempBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
||
1702 | if (fi.exists()) |
||
15520 | fschmid | 1703 | { |
22708 | jghali | 1704 | QFile f2(QDir::toNativeSeparators(tempBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
1705 | f2.remove(); |
||
15520 | fschmid | 1706 | } |
22708 | jghali | 1707 | QFileInfo fiD(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key())); |
1708 | if ((fiD.exists()) && (fiD.isDir())) |
||
14715 | fschmid | 1709 | { |
22708 | jghali | 1710 | QDir dd = QDir(QDir::toNativeSeparators(tempBView->ScFilename)); |
1711 | QDir d(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key()), "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks); |
||
1712 | if ((d.exists()) && (d.count() != 0)) |
||
14715 | fschmid | 1713 | { |
22708 | jghali | 1714 | for (uint dc = 0; dc < d.count(); ++dc) |
14715 | fschmid | 1715 | { |
22708 | jghali | 1716 | QFile::remove(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key() + "/" + d[dc])); |
14715 | fschmid | 1717 | } |
1718 | } |
||
22708 | jghali | 1719 | dd.rmdir(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key())); |
14715 | fschmid | 1720 | } |
22708 | jghali | 1721 | QString name = it.key(); |
1722 | tempBView->objectMap.erase(it); |
||
1723 | QList<QListWidgetItem *> itL = tempBView->findItems(name, Qt::MatchExactly); |
||
1724 | if (itL.count() > 0) |
||
1725 | { |
||
1726 | QListWidgetItem *ite = itL.at(0); |
||
1727 | delete tempBView->takeItem(tempBView->row(ite)); |
||
1728 | } |
||
14715 | fschmid | 1729 | } |
22708 | jghali | 1730 | emit updateRecentMenue(); |
14715 | fschmid | 1731 | } |
22708 | jghali | 1732 | reloadLib(activeBView->ScFilename); |
14715 | fschmid | 1733 | } |
1734 | |||
23035 | jghali | 1735 | void Biblio::objFromMenu(QString text) |
3 | paul | 1736 | { |
11548 | fschmid | 1737 | QString nam = ""; |
1738 | QString tmp; |
||
9819 | fschmid | 1739 | if (!activeBView->canWrite) |
1740 | return; |
||
11548 | fschmid | 1741 | nam = getObjectName(text); |
8336 | fschmid | 1742 | if (Frame3->currentIndex() == 1) |
5787 | fschmid | 1743 | { |
11548 | fschmid | 1744 | if (nam.isEmpty()) |
23035 | jghali | 1745 | nam = tr("Object") + tmp.setNum(m_tempCount); |
11548 | fschmid | 1746 | if (activeBView->objectMap.contains(nam)) |
23035 | jghali | 1747 | nam += "("+ tmp.setNum(m_tempCount) + ")"; |
1748 | m_tempCount++; |
||
5787 | fschmid | 1749 | } |
1750 | else |
||
11548 | fschmid | 1751 | { |
1752 | if (nam.isEmpty()) |
||
1753 | nam = tr("Object") + tmp.setNum(activeBView->objectMap.count()); |
||
1754 | if (activeBView->objectMap.contains(nam)) |
||
23035 | jghali | 1755 | nam += "("+ tmp.setNum(m_tempCount) + ")"; |
11548 | fschmid | 1756 | } |
18194 | fschmid | 1757 | Query dia(this, "tt", 1, tr("&Name:"), tr("New Entry")); |
17895 | fschmid | 1758 | dia.setValidator(QRegExp("[\\w()]+")); |
17235 | craig | 1759 | dia.setEditText(nam, true); |
1760 | dia.setTestList(activeBView->objectMap.keys()); |
||
1761 | if (dia.exec()) |
||
1762 | nam = dia.getEditText(); |
||
248 | Franz | 1763 | else |
1764 | return; |
||
6199 | fschmid | 1765 | QString ff = text; |
16577 | craig | 1766 | activeBView->checkAndChange(ff, QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + nam + ".sce")), QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename))); |
2834 | cbradney | 1767 | ScPreview *pre = new ScPreview(); |
14763 | cbradney | 1768 | QPixmap pm = QPixmap::fromImage(pre->createPreview(ff)); |
23035 | jghali | 1769 | activeBView->addObject(nam, QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + nam + ".sce")), pm); |
23060 | craig | 1770 | if (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews) |
15520 | fschmid | 1771 | { |
1772 | QDir thumbs(activeBView->ScFilename); |
||
1773 | if (thumbs.exists()) |
||
1774 | { |
||
23060 | craig | 1775 | if ((activeBView->canWrite) && (PrefsManager::instance().appPrefs.scrapbookPrefs.writePreviews)) |
15520 | fschmid | 1776 | thumbs.mkdir(".ScribusThumbs"); |
1777 | } |
||
16577 | craig | 1778 | pm.save(QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/.ScribusThumbs/" + nam +".png")), "PNG"); |
15520 | fschmid | 1779 | } |
14763 | cbradney | 1780 | pm = pm.scaled(60, 60, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
9819 | fschmid | 1781 | QPixmap pm2(60, 60); |
10737 | fschmid | 1782 | pm2.fill(palette().color(QPalette::Base)); |
9819 | fschmid | 1783 | QPainter p; |
1784 | p.begin(&pm2); |
||
1785 | p.drawPixmap(30 - pm.width() / 2, 30 - pm.height() / 2, pm); |
||
1786 | p.end(); |
||
15552 | fschmid | 1787 | QListWidgetItem *item = new QListWidgetItem(QIcon(pm2), nam, activeBView); |
21181 | fschmid | 1788 | item->setToolTip(nam); |
15552 | fschmid | 1789 | activeBView->objectMap[nam].widgetItem = item; |
30 | Franz | 1790 | delete pre; |
22708 | jghali | 1791 | |
8336 | fschmid | 1792 | if (Frame3->currentIndex() == 1) |
5787 | fschmid | 1793 | { |
23060 | craig | 1794 | if (tempBView->objectMap.count() > PrefsManager::instance().appPrefs.scrapbookPrefs.numScrapbookCopies) |
5787 | fschmid | 1795 | { |
1796 | QMap<QString,BibView::Elem>::Iterator it; |
||
1797 | it = tempBView->objectMap.begin(); |
||
10516 | cbradney | 1798 | QFile f(it.value().Data); |
5787 | fschmid | 1799 | f.remove(); |
16577 | craig | 1800 | QFileInfo fi(QDir::toNativeSeparators(tempBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
5787 | fschmid | 1801 | if (fi.exists()) |
1802 | { |
||
16577 | craig | 1803 | QFile f2(QDir::toNativeSeparators(tempBView->ScFilename + "/.ScribusThumbs/" + it.key() + ".png")); |
5787 | fschmid | 1804 | f2.remove(); |
1805 | } |
||
16577 | craig | 1806 | QFileInfo fiD(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key())); |
8295 | fschmid | 1807 | if ((fiD.exists()) && (fiD.isDir())) |
1808 | { |
||
16577 | craig | 1809 | QDir dd = QDir(QDir::toNativeSeparators(tempBView->ScFilename)); |
1810 | QDir d(QDir::toNativeSeparators(tempBView->ScFilename + "/" + it.key()), |