summaryrefslogtreecommitdiffstats
path: root/test/ruby/test_require.rb
diff options
context:
space:
mode:
authorsvn <svn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-07 17:32:55 +0000
committersvn <svn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-07 17:32:55 +0000
commit8c60a30d6a10896b22941faead73ed20721c591e (patch)
treead9f7673d7629be65347d0441885ea9fab0e5711 /test/ruby/test_require.rb
parentaa8e1885265ac1052cbf12aa9a5c045c3c805e8d (diff)
downloadruby-8c60a30d6a10896b22941faead73ed20721c591e.tar.gz
ruby-8c60a30d6a10896b22941faead73ed20721c591e.tar.xz
ruby-8c60a30d6a10896b22941faead73ed20721c591e.zip
* 2009-05-08
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_require.rb')
0 files changed, 0 insertions, 0 deletions
150'>150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "collect4output.h"

#include "scribusdoc.h"
#include "scribuscore.h"
#include "util.h"
#include "prefscontext.h"
#include "prefsfile.h"
#include "prefsmanager.h"
#include "commonstrings.h"
#include "undomanager.h"
#include "filewatcher.h"
#include "pageitem.h"
#include "scraction.h"
#include "scpattern.h"
#include "util_file.h"

#include <QMessageBox>
#include <QString>
#include <QMap>
#include <QDir>

CollectForOutput::CollectForOutput(ScribusDoc* doc, bool withFontsA, bool withProfilesA, bool compressDocA)
	: QObject(ScCore),
	m_Doc(0)
{
	m_Doc=doc;
	outputDirectory = QString();
	compressDoc = compressDocA;
	withFonts = withFontsA;
	withProfiles = withProfilesA;
	dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
	collectedFiles.clear();
}

bool CollectForOutput::newDirDialog()
{
	QString curDir = QDir::currentPath();
	if (ScCore->usingGUI())
	{
		QString wdir = ".";
		QString prefsDocDir = PrefsManager::instance()->documentDir();
		if (!prefsDocDir.isEmpty())
			wdir = dirs->get("collect", prefsDocDir);
		else
			wdir = dirs->get("collect", ".");
		outputDirectory = ScCore->primaryMainWindow()->CFileDialog(wdir, tr("Choose a Directory"), "", "", fdDirectoriesOnly, &compressDoc, &withFonts, &withProfiles);
	}
	if (outputDirectory.isEmpty())
		return false;
	if (!outputDirectory.endsWith("/"))
		outputDirectory += "/";
	QDir dir(outputDirectory);
	if (!dir.exists())
	{
		bool created = dir.mkpath(outputDirectory);
		if (!created)
		{
			QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
							 "<qt>" + tr("Cannot create directory:\n%1").arg(outputDirectory) + "</qt>",
							 CommonStrings::tr_OK);
			return false;
		}
	}
	return true;
}

QString CollectForOutput::collect()
{
	if (!newDirDialog())
		return "";
	ScCore->fileWatcher->forceScan();
	ScCore->fileWatcher->stop();
	dirs->set("collect", outputDirectory.left(outputDirectory.lastIndexOf("/",-2)));
	ScCore->primaryMainWindow()->setStatusBarInfoText( tr("Collecting..."));

	if (!collectItems())
	{
		QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
							 "<qt>" + tr("Cannot collect all files for output for file:\n%1").arg(newName) + "</qt>",
							 CommonStrings::tr_OK);
		return "";
	}

	if (withFonts)
		collectFonts();
	if (withProfiles)
		collectProfiles();

	/* collect document must go last because of image paths changes
	in collectItems() */
	if (!collectDocument())
	{
		QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, "<qt>" + tr("Cannot collect the file: \n%1").arg(newName) + "</qt>", CommonStrings::tr_OK);
		return "";
	}

	QDir::setCurrent(outputDirectory);
	ScCore->primaryMainWindow()->updateActiveWindowCaption(newName);
	UndoManager::instance()->renameStack(newName);
	ScCore->primaryMainWindow()->scrActions["fileRevert"]->setEnabled(false);
	ScCore->primaryMainWindow()->updateRecent(newName);
	ScCore->primaryMainWindow()->setStatusBarInfoText("");
	ScCore->primaryMainWindow()->mainWindowProgressBar->reset();
	ScCore->fileWatcher->start();
	collectedFiles.clear();
	return newName;
}

bool CollectForOutput::collectDocument()
{
	QFileInfo fi = QFileInfo(outputDirectory);
	newName = outputDirectory;
	if (!fi.exists())
		return false;
	if (!fi.isDir() || !fi.isWritable())
		return false;

	if (m_Doc->hasName)
	{
		QFileInfo fis(m_Doc->DocName);
		newName += fis.fileName();
	}
	else
		newName += m_Doc->DocName+".sla";

	m_Doc->hasName = true;
	if (compressDoc)
	{
		if (!newName.endsWith(".gz"))
			newName += ".gz";
		else
		{
			if (newName.endsWith(".gz"))
				newName = newName.remove(".gz");
		}
	}

	if (!overwrite(ScCore->primaryMainWindow(), newName))
		return false;
	if (!ScCore->primaryMainWindow()->DoFileSave(newName))
		return false;
	return true;
}

bool CollectForOutput::collectItems()
{
	uint counter = 0;
	for (uint lc = 0; lc < 3; ++lc)
	{
		PageItem* ite = NULL;
		switch (lc)
		{
			case 0:
				counter = m_Doc->MasterItems.count();
				break;
			case 1:
				counter = m_Doc->DocItems.count();
				break;
			case 2:
				counter = m_Doc->FrameItems.count();
				break;
		}