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