Sophie

Sophie

distrib > Mandriva > current > x86_64 > by-pkgid > 4272c97b1af3db3f39a3b697bcba7e48 > files > 1012

albumshaper-2.1-7mdv2010.1.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AlbumShaper: fileTools.cpp File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>fileTools.cpp File Reference</h1><code>#include &lt;fstream&gt;</code><br/>
<code>#include &lt;qstring.h&gt;</code><br/>
<code>#include &lt;qfile.h&gt;</code><br/>
<code>#include &lt;qdir.h&gt;</code><br/>
<code>#include &lt;qlibrary.h&gt;</code><br/>
<code>#include &quot;<a class="el" href="fileTools_8h_source.html">fileTools.h</a>&quot;</code><br/>
<div class="dynheader">
Include dependency graph for fileTools.cpp:</div>
<div class="dynsection">
</div>

<p><a href="fileTools_8cpp_source.html">Go to the source code of this file.</a></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="fileTools_8cpp.html#a303fab00942c01cb4872793ee0abe508">moveFile</a> (QString oldName, QString newName)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="fileTools_8cpp.html#af41848ecf008f6b6579f5b0975faea5a">copyFile</a> (QString oldFilePath, QString newFilePath)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Copies a file from one location to another.  <a href="#af41848ecf008f6b6579f5b0975faea5a"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QString&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="fileTools_8cpp.html#a1fe04c01b9364448467257879e4ba5ff">fixFilename</a> (QString filename)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Replaces invalid characters in filenames with valid ones.  <a href="#a1fe04c01b9364448467257879e4ba5ff"></a><br/></td></tr>
</table>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="af41848ecf008f6b6579f5b0975faea5a"></a><!-- doxytag: member="fileTools.cpp::copyFile" ref="af41848ecf008f6b6579f5b0975faea5a" args="(QString oldFilePath, QString newFilePath)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool copyFile </td>
          <td>(</td>
          <td class="paramtype">QString&nbsp;</td>
          <td class="paramname"> <em>oldFilePath</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">QString&nbsp;</td>
          <td class="paramname"> <em>newFilePath</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Copies a file from one location to another. </p>

<p>Definition at line <a class="el" href="fileTools_8cpp_source.html#l00061">61</a> of file <a class="el" href="fileTools_8cpp_source.html">fileTools.cpp</a>.</p>

<p>References <a class="el" href="blur_8cpp_source.html#l00080">buffer</a>.</p>

<p>Referenced by <a class="el" href="album_8cpp_source.html#l00616">Album::exportCompressedWebAlbum()</a>, <a class="el" href="album_8cpp_source.html#l00726">Album::exportLargeImages()</a>, <a class="el" href="album_8cpp_source.html#l00889">Album::exportSubalbumImages()</a>, <a class="el" href="album_8cpp_source.html#l01322">Album::exportThemeResources()</a>, <a class="el" href="fileTools_8cpp_source.html#l00040">moveFile()</a>, <a class="el" href="photo_8cpp_source.html#l00123">Photo::setImage()</a>, and <a class="el" href="wallpaperTools_8cpp_source.html#l00034">setWallpaper()</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00062"></a>00062 {
<a name="l00063"></a>00063   <span class="comment">//same file, no need to copy</span>
<a name="l00064"></a>00064   <span class="keywordflow">if</span>(oldFilePath.compare(newFilePath) == 0)
<a name="l00065"></a>00065     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067   <span class="comment">//load both files</span>
<a name="l00068"></a>00068   QFile oldFile(oldFilePath);
<a name="l00069"></a>00069   QFile newFile(newFilePath);
<a name="l00070"></a>00070   <span class="keywordtype">bool</span> openOld = oldFile.open( IO_ReadOnly );
<a name="l00071"></a>00071   <span class="keywordtype">bool</span> openNew = newFile.open( IO_WriteOnly );
<a name="l00072"></a>00072 
<a name="l00073"></a>00073   <span class="comment">//if either file fails to open bail</span>
<a name="l00074"></a>00074   <span class="keywordflow">if</span>(!openOld || !openNew) { <span class="keywordflow">return</span> <span class="keyword">false</span>; }
<a name="l00075"></a>00075 
<a name="l00076"></a>00076   <span class="comment">//copy contents</span>
<a name="l00077"></a>00077   uint BUFFER_SIZE = 16000;
<a name="l00078"></a>00078   <span class="keywordtype">char</span>* <a class="code" href="blur_8cpp.html#afa761c0753ecc94346e155a39bd9ed9c">buffer</a> = <span class="keyword">new</span> <span class="keywordtype">char</span>[BUFFER_SIZE];
<a name="l00079"></a>00079   <span class="keywordflow">while</span>(!oldFile.atEnd())
<a name="l00080"></a>00080   {
<a name="l00081"></a>00081     Q_ULONG len = oldFile.readBlock( buffer, BUFFER_SIZE );
<a name="l00082"></a>00082     newFile.writeBlock( buffer, len );
<a name="l00083"></a>00083   }
<a name="l00084"></a>00084 
<a name="l00085"></a>00085   <span class="comment">//deallocate buffer</span>
<a name="l00086"></a>00086   <span class="keyword">delete</span>[] buffer;
<a name="l00087"></a>00087   buffer = NULL;
<a name="l00088"></a>00088   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00089"></a>00089 }
</pre></div></p>

</div>
</div>
<a class="anchor" id="a1fe04c01b9364448467257879e4ba5ff"></a><!-- doxytag: member="fileTools.cpp::fixFilename" ref="a1fe04c01b9364448467257879e4ba5ff" args="(QString filename)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">QString fixFilename </td>
          <td>(</td>
          <td class="paramtype">QString&nbsp;</td>
          <td class="paramname"> <em>filename</em></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Replaces invalid characters in filenames with valid ones. </p>

<p>Definition at line <a class="el" href="fileTools_8cpp_source.html#l00137">137</a> of file <a class="el" href="fileTools_8cpp_source.html">fileTools.cpp</a>.</p>

<p>Referenced by <a class="el" href="titleWidget_8cpp_source.html#l00800">TitleWidget::exportLargeImages()</a>, and <a class="el" href="titleWidget_8cpp_source.html#l00700">TitleWidget::exportSmallWebGallery()</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00138"></a>00138 { 
<a name="l00139"></a>00139   filename.replace( QChar(<span class="charliteral">&#39; &#39;</span>), <span class="stringliteral">&quot;_&quot;</span> );
<a name="l00140"></a>00140   filename.replace( <span class="stringliteral">&quot;&lt;&quot;</span>, <span class="stringliteral">&quot;&quot;</span> );
<a name="l00141"></a>00141   filename.replace( <span class="stringliteral">&quot;&gt;&quot;</span>, <span class="stringliteral">&quot;&quot;</span> );
<a name="l00142"></a>00142   filename.replace( <span class="stringliteral">&quot;&amp;&quot;</span>, <span class="stringliteral">&quot;and&quot;</span> );
<a name="l00143"></a>00143   filename.replace( <span class="stringliteral">&quot;\&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span> );
<a name="l00144"></a>00144   filename.replace( <span class="stringliteral">&quot;\&#39;&quot;</span>, <span class="stringliteral">&quot;&quot;</span> );
<a name="l00145"></a>00145   filename.replace( <span class="stringliteral">&quot;?&quot;</span>, <span class="stringliteral">&quot;&quot;</span> );
<a name="l00146"></a>00146   <span class="keywordflow">return</span> filename;
<a name="l00147"></a>00147 }
</pre></div></p>

</div>
</div>
<a class="anchor" id="a303fab00942c01cb4872793ee0abe508"></a><!-- doxytag: member="fileTools.cpp::moveFile" ref="a303fab00942c01cb4872793ee0abe508" args="(QString oldName, QString newName)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool moveFile </td>
          <td>(</td>
          <td class="paramtype">QString&nbsp;</td>
          <td class="paramname"> <em>oldName</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">QString&nbsp;</td>
          <td class="paramname"> <em>newName</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Definition at line <a class="el" href="fileTools_8cpp_source.html#l00040">40</a> of file <a class="el" href="fileTools_8cpp_source.html">fileTools.cpp</a>.</p>

<p>References <a class="el" href="fileTools_8cpp_source.html#l00061">copyFile()</a>.</p>

<p>Referenced by <a class="el" href="photo_8cpp_source.html#l00475">Photo::applyTransformation()</a>, <a class="el" href="album_8cpp_source.html#l00889">Album::exportSubalbumImages()</a>, and <a class="el" href="album_8cpp_source.html#l01126">Album::reorderSubalbumImages()</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00041"></a>00041 {
<a name="l00042"></a>00042   QDir rootDir;
<a name="l00043"></a>00043   
<a name="l00044"></a>00044   <span class="comment">//attempt to rename file</span>
<a name="l00045"></a>00045   <span class="keywordflow">if</span>(!rootDir.rename( oldName, newName))
<a name="l00046"></a>00046   {
<a name="l00047"></a>00047     <span class="comment">//move failed, copy file and remove original</span>
<a name="l00048"></a>00048     
<a name="l00049"></a>00049     <span class="comment">//copy failed! sound alert and do not remove original!!!</span>
<a name="l00050"></a>00050     <span class="keywordflow">if</span>(!<a class="code" href="fileTools_8cpp.html#af41848ecf008f6b6579f5b0975faea5a" title="Copies a file from one location to another.">copyFile</a>(oldName, newName))
<a name="l00051"></a>00051       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00052"></a>00052 
<a name="l00053"></a>00053     <span class="comment">//copy succeded, remove original and return</span>
<a name="l00054"></a>00054     rootDir.remove(oldName);
<a name="l00055"></a>00055   }
<a name="l00056"></a>00056   
<a name="l00057"></a>00057   <span class="comment">//move succeeded either directly or via copying and removing original file</span>
<a name="l00058"></a>00058   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00059"></a>00059 }
</pre></div></p>

</div>
</div>
</div>
<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>