@ -21,17 +21,17 @@
# include <config.h>
# endif
# include < qevent.h>
# include < qdragobject.h>
# include < qfile.h>
# include < qvaluelist.h>
# include < qcursor.h>
# include < qbuffer.h>
# include < qlistview.h>
# include < qclipboard.h>
# include < qheader.h>
# include < qtextstream.h>
# include < qtimer.h>
# include < nt qevent.h>
# include < nt qdragobject.h>
# include < nt qfile.h>
# include < nt qvaluelist.h>
# include < nt qcursor.h>
# include < nt qbuffer.h>
# include < nt qlistview.h>
# include < nt qclipboard.h>
# include < nt qheader.h>
# include < nt qtextstream.h>
# include < nt qtimer.h>
# include <kapplication.h>
# include <kio/netaccess.h>
@ -69,12 +69,12 @@
namespace KBibTeX
{
DocumentListView : : DocumentListView ( KBibTeX : : DocumentWidget * docWidget , bool isReadOnly , QWidget * parent , const char * name )
DocumentListView : : DocumentListView ( KBibTeX : : DocumentWidget * docWidget , bool isReadOnly , T QWidget * parent , const char * name )
: KListView ( parent , name ) , m_docWidget ( docWidget ) , m_bibtexFile ( NULL ) , m_contextMenu ( NULL ) , m_headerMenu ( NULL ) , m_isReadOnly ( isReadOnly ) , m_newElementCounter ( 1 )
{
setAllColumnsShowFocus ( true ) ;
setShowSortIndicator ( true ) ;
setSelectionMode ( QListView: : Extended ) ;
setSelectionMode ( T QListView: : Extended ) ;
header ( ) - > setClickEnabled ( TRUE ) ;
header ( ) - > setMovingEnabled ( TRUE ) ;
buildColumns ( ) ;
@ -85,9 +85,9 @@ namespace KBibTeX
setDropVisualizer ( TRUE ) ;
connect ( header ( ) , SIGNAL ( clicked ( int ) ) , this , SLOT ( setSortingColumn ( int ) ) ) ;
connect ( this , SIGNAL ( contextMenu ( KListView * , QListViewItem * , const QPoint & ) ) , this , SLOT ( showBibtexListContextMenu ( KListView * , QListViewItem * , const QPoint & ) ) ) ;
connect ( this , SIGNAL ( doubleClicked ( QListViewItem* , const QPoint& , int ) ) , this , SLOT ( slotDoubleClick ( QListViewItem* ) ) ) ;
connect ( this , SIGNAL ( dropped ( QDropEvent* , QListViewItem* ) ) , this , SLOT ( slotDropped ( QDropEvent* , QListViewItem* ) ) ) ;
connect ( this , SIGNAL ( contextMenu ( KListView * , T QListViewItem * , const T QPoint & ) ) , this , SLOT ( showBibtexListContextMenu ( KListView * , T QListViewItem * , const T QPoint & ) ) ) ;
connect ( this , SIGNAL ( doubleClicked ( T QListViewItem* , const T QPoint& , int ) ) , this , SLOT ( slotDoubleClick ( T QListViewItem* ) ) ) ;
connect ( this , SIGNAL ( dropped ( T QDropEvent* , T QListViewItem* ) ) , this , SLOT ( slotDropped ( T QDropEvent* , T QListViewItem* ) ) ) ;
}
DocumentListView : : ~ DocumentListView ( )
@ -115,7 +115,7 @@ namespace KBibTeX
void DocumentListView : : setItems ( )
{
QApplication: : setOverrideCursor ( Qt: : waitCursor ) ;
T QApplication: : setOverrideCursor ( T Qt: : waitCursor ) ;
KProgressDialog * prgDlg = new KProgressDialog ( this , " prgDlg " , i18n ( " List View " ) , i18n ( " Updating main view ... " ) , TRUE ) ;
prgDlg - > show ( ) ;
@ -145,7 +145,7 @@ namespace KBibTeX
updateVisiblity ( ) ;
QApplication: : restoreOverrideCursor ( ) ;
T QApplication: : restoreOverrideCursor ( ) ;
}
void DocumentListView : : insertItems ( BibTeX : : File * items , KBibTeX : : DocumentListViewItem * after )
@ -167,9 +167,9 @@ namespace KBibTeX
if ( m_bibtexFile - > containsKey ( newEntry - > id ( ) ) )
{
int counter = 0 ;
QString newId = QString( newEntry - > id ( ) ) . append ( ' _ ' ) . append ( QString: : number ( + + counter ) ) ;
T QString newId = T QString( newEntry - > id ( ) ) . append ( ' _ ' ) . append ( T QString: : number ( + + counter ) ) ;
while ( m_bibtexFile - > containsKey ( newId ) )
newId = QString( newEntry - > id ( ) ) . append ( ' _ ' ) . append ( QString: : number ( + + counter ) ) ;
newId = T QString( newEntry - > id ( ) ) . append ( ' _ ' ) . append ( T QString: : number ( + + counter ) ) ;
newEntry - > setId ( newId ) ;
}
element = newEntry ;
@ -185,7 +185,7 @@ namespace KBibTeX
m_unreadItems . append ( after ) ;
emit modified ( ) ;
QTimer: : singleShot ( 3500 , this , SLOT ( makeNewItemsUnread ( ) ) ) ;
T QTimer: : singleShot ( 3500 , this , SLOT ( makeNewItemsUnread ( ) ) ) ;
return after ;
}
@ -197,7 +197,7 @@ namespace KBibTeX
void DocumentListView : : updateVisiblity ( )
{
QListViewItemIterator it ( this ) ;
T QListViewItemIterator it ( this ) ;
while ( it . current ( ) )
{
DocumentListViewItem * kblvi = dynamic_cast < DocumentListViewItem * > ( it . current ( ) ) ;
@ -263,7 +263,7 @@ namespace KBibTeX
for ( int i = 0 ; i < = ( int ) BibTeX : : EntryField : : ftYear - ( int ) BibTeX : : EntryField : : ftAbstract ; i + + )
{
BibTeX : : EntryField : : FieldType fieldType = ( BibTeX : : EntryField : : FieldType ) ( i + ( int ) BibTeX : : EntryField : : ftAbstract ) ;
QString label = Settings : : fieldTypeToI18NString ( fieldType ) ;
T QString label = Settings : : fieldTypeToI18NString ( fieldType ) ;
item = m_headerMenu - > insertItem ( label , ( int ) fieldType + 2 ) ;
m_headerMenu - > setItemChecked ( item , settings - > editing_MainListColumnsWidth [ i + 2 ] > 0 ) ;
}
@ -272,11 +272,11 @@ namespace KBibTeX
void DocumentListView : : deleteSelected ( )
{
QListViewItemIterator it ( this , QListViewItemIterator: : Selected | QListViewItemIterator: : Visible ) ;
T QListViewItemIterator it ( this , T QListViewItemIterator: : Selected | T QListViewItemIterator: : Visible ) ;
if ( it . current ( ) = = NULL ) return ;
QListViewItem * above = it . current ( ) - > itemAbove ( ) ;
QValueList< DocumentListViewItem * > toBeDeleted ;
T QListViewItem * above = it . current ( ) - > itemAbove ( ) ;
T QValueList< DocumentListViewItem * > toBeDeleted ;
while ( it . current ( ) )
{
DocumentListViewItem * kblvi = dynamic_cast < DocumentListViewItem * > ( it . current ( ) ) ;
@ -284,7 +284,7 @@ namespace KBibTeX
it + + ;
}
for ( QValueList< DocumentListViewItem * > : : Iterator it = toBeDeleted . begin ( ) ; it ! = toBeDeleted . end ( ) ; + + it )
for ( T QValueList< DocumentListViewItem * > : : Iterator it = toBeDeleted . begin ( ) ; it ! = toBeDeleted . end ( ) ; + + it )
{
m_bibtexFile - > deleteElement ( ( * it ) - > element ( ) ) ;
takeItem ( * it ) ;
@ -297,11 +297,11 @@ namespace KBibTeX
emit modified ( ) ;
}
const QValueList< BibTeX : : Element * > DocumentListView : : selectedItems ( )
const T QValueList< BibTeX : : Element * > DocumentListView : : selectedItems ( )
{
QValueList< BibTeX : : Element * > result ;
T QValueList< BibTeX : : Element * > result ;
QListViewItemIterator it ( this , QListViewItemIterator: : Selected ) ;
T QListViewItemIterator it ( this , T QListViewItemIterator: : Selected ) ;
while ( it . current ( ) )
{
DocumentListViewItem * kblvi = dynamic_cast < DocumentListViewItem * > ( it . current ( ) ) ;
@ -313,33 +313,33 @@ namespace KBibTeX
return result ;
}
QString DocumentListView : : selectedToBibTeXText ( )
T QString DocumentListView : : selectedToBibTeXText ( )
{
BibTeX : : FileExporterBibTeX * exporter = new BibTeX : : FileExporterBibTeX ( ) ;
exporter - > setEncoding ( " latex " ) ;
QBuffer buffer ;
T QBuffer buffer ;
buffer . open ( IO_WriteOnly ) ;
QValueList< BibTeX : : Element * > selectedElements = selectedItems ( ) ;
for ( QValueList< BibTeX : : Element * > : : iterator it = selectedElements . begin ( ) ; it ! = selectedElements . end ( ) ; + + it )
T QValueList< BibTeX : : Element * > selectedElements = selectedItems ( ) ;
for ( T QValueList< BibTeX : : Element * > : : iterator it = selectedElements . begin ( ) ; it ! = selectedElements . end ( ) ; + + it )
exporter - > save ( & buffer , * it ) ;
buffer . close ( ) ;
delete exporter ;
buffer . open ( IO_ReadOnly ) ;
QTextStream in ( & buffer ) ;
in . setEncoding ( QTextStream: : UnicodeUTF8 ) ;
QString result = in . read ( ) ;
T QTextStream in ( & buffer ) ;
in . setEncoding ( T QTextStream: : UnicodeUTF8 ) ;
T QString result = in . read ( ) ;
buffer . close ( ) ;
return result ;
}
QString DocumentListView : : selectedToBibTeXRefs ( )
T QString DocumentListView : : selectedToBibTeXRefs ( )
{
QString refs ;
QValueList< BibTeX : : Element * > selectedElements = selectedItems ( ) ;
for ( QValueList< BibTeX : : Element * > : : iterator it = selectedElements . begin ( ) ; it ! = selectedElements . end ( ) ; + + it )
T QString refs ;
T QValueList< BibTeX : : Element * > selectedElements = selectedItems ( ) ;
for ( T QValueList< BibTeX : : Element * > : : iterator it = selectedElements . begin ( ) ; it ! = selectedElements . end ( ) ; + + it )
{
BibTeX : : Entry * entry = dynamic_cast < BibTeX : : Entry * > ( * it ) ;
if ( entry = = NULL ) continue ;
@ -348,7 +348,7 @@ namespace KBibTeX
refs . append ( " , " ) ;
refs . append ( entry - > id ( ) ) ;
}
return QString( " \\ cite{%1} " ) . arg ( refs ) ;
return T QString( " \\ cite{%1} " ) . arg ( refs ) ;
}
void DocumentListView : : copy ( )
@ -373,11 +373,11 @@ namespace KBibTeX
if ( dlvi = = NULL )
dlvi = dynamic_cast < KBibTeX : : DocumentListViewItem * > ( currentItem ( ) ) ;
QString clipboardText = kapp - > clipboard ( ) - > text ( ) ;
T QString clipboardText = kapp - > clipboard ( ) - > text ( ) ;
return paste ( clipboardText , dlvi ) ;
}
bool DocumentListView : : paste ( const QString& text , DocumentListViewItem * at )
bool DocumentListView : : paste ( const T QString& text , DocumentListViewItem * at )
{
Settings * settings = Settings : : self ( m_bibtexFile ) ;
@ -454,11 +454,11 @@ namespace KBibTeX
popup - > insertItem ( Settings : : fieldTypeToI18NString ( ft ) , i ) ;
}
popup - > insertSeparator ( ) ;
QIconSet cancelPixmap = KGlobal : : iconLoader ( ) - > loadIconSet ( " cancel " , KIcon : : Small ) ;
T QIconSet cancelPixmap = KGlobal : : iconLoader ( ) - > loadIconSet ( " cancel " , KIcon : : Small ) ;
int cancelId = popup - > insertItem ( cancelPixmap , i18n ( " Cancel " ) ) ;
// show popup menu
int selectedId = popup - > exec ( QCursor: : pos ( ) ) ;
int selectedId = popup - > exec ( T QCursor: : pos ( ) ) ;
if ( selectedId = = cancelId | | selectedId = = - 1 )
return FALSE ; // cancel menu
@ -473,7 +473,7 @@ namespace KBibTeX
else if ( field - > value ( ) ! = NULL )
delete field - > value ( ) ;
QString encodedText = BibTeX : : EncoderLaTeX : : currentEncoderLaTeX ( ) - > encode ( text ) ;
T QString encodedText = BibTeX : : EncoderLaTeX : : currentEncoderLaTeX ( ) - > encode ( text ) ;
// create new value from clipboard's content
BibTeX : : Value * value = new BibTeX : : Value ( ) ;
@ -495,13 +495,13 @@ namespace KBibTeX
void DocumentListView : : selectAll ( )
{
QListView: : selectAll ( true ) ;
T QListView: : selectAll ( true ) ;
}
/* void DocumentListView::sendSelectedToLyx()
{
QStringList refsToSend ;
QListViewItemIterator it ( this , QListViewItemIterator: : Selected ) ;
T QStringList refsToSend ;
T QListViewItemIterator it ( this , T QListViewItemIterator: : Selected ) ;
while ( it . current ( ) )
{
DocumentListViewItem * kblvi = dynamic_cast < DocumentListViewItem * > ( it . current ( ) ) ;
@ -512,28 +512,28 @@ namespace KBibTeX
}
Settings * settings = Settings : : self ( m_bibtexFile ) ;
QString lyxPipeFilename = settings - > detectLyXInPipe ( ) ;
T QString lyxPipeFilename = settings - > detectLyXInPipe ( ) ;
kdDebug ( ) < < " sendSelectedToLyx: lyxPipeFilename= " < < lyxPipeFilename < < endl ;
QFile pipe ( lyxPipeFilename ) ;
T QFile pipe ( lyxPipeFilename ) ;
if ( pipe . exists ( ) & & pipe . open ( IO_WriteOnly ) )
{
QTextStream * writer = new QTextStream( & pipe ) ;
QString msg = " LYXCMD:kbibtex:citation-insert: " + refsToSend . join ( " , " ) ;
T QTextStream * writer = new T QTextStream( & pipe ) ;
T QString msg = " LYXCMD:kbibtex:citation-insert: " + refsToSend . join ( " , " ) ;
* writer < < msg < < endl ;
delete writer ;
pipe . close ( ) ;
}
else
KMessageBox : : error ( this , ( lyxPipeFilename . isEmpty ( ) ? i18n ( " Cannot establish a link to LyX " ) : QString( i18n ( " Cannot establish a link to LyX using the pipe \" %1 \" " ) ) . arg ( lyxPipeFilename ) ) + i18n ( " \n Maybe LyX is not running? " ) , i18n ( " Error communicating with LyX " ) ) ;
KMessageBox : : error ( this , ( lyxPipeFilename . isEmpty ( ) ? i18n ( " Cannot establish a link to LyX " ) : T QString( i18n ( " Cannot establish a link to LyX using the pipe \" %1 \" " ) ) . arg ( lyxPipeFilename ) ) + i18n ( " \n Maybe LyX is not running? " ) , i18n ( " Error communicating with LyX " ) ) ;
} */
void DocumentListView : : slotDoubleClick ( QListViewItem * item )
void DocumentListView : : slotDoubleClick ( T QListViewItem * item )
{
DocumentListViewItem * dlvi = dynamic_cast < DocumentListViewItem * > ( item ) ;
if ( dlvi ! = NULL ) emit executed ( dlvi ) ;
}
void DocumentListView : : filter ( const QString & text , BibTeX : : Element : : FilterType filterType , BibTeX : : EntryField : : FieldType fieldType )
void DocumentListView : : filter ( const T QString & text , BibTeX : : Element : : FilterType filterType , BibTeX : : EntryField : : FieldType fieldType )
{
m_filter = text ;
m_filterType = filterType ;
@ -563,7 +563,7 @@ namespace KBibTeX
}
}
void DocumentListView : : showBibtexListContextMenu ( KListView * , QListViewItem * , const QPoint & p )
void DocumentListView : : showBibtexListContextMenu ( KListView * , T QListViewItem * , const T QPoint & p )
{
if ( m_contextMenu ! = NULL )
{
@ -576,25 +576,25 @@ namespace KBibTeX
{
Settings * settings = Settings : : self ( m_bibtexFile ) ;
settings - > editing_MainListSortingColumn = column ;
settings - > editing_MainListSortingOrder = ( sortOrder ( ) = = Qt: : Ascending ) ? 1 : - 1 ;
settings - > editing_MainListSortingOrder = ( sortOrder ( ) = = T Qt: : Ascending ) ? 1 : - 1 ;
}
bool DocumentListView : : acceptDrag ( QDropEvent * event ) const
bool DocumentListView : : acceptDrag ( T QDropEvent * event ) const
{
if ( event - > source ( ) = = this ) return false ;
return QTextDrag: : canDecode ( event ) | | QUriDrag: : canDecode ( event ) ;
return T QTextDrag: : canDecode ( event ) | | T QUriDrag: : canDecode ( event ) ;
}
void DocumentListView : : startDrag ( )
{
Settings * settings = Settings : : self ( m_bibtexFile ) ;
QDragObject * d = new QTextDrag( settings - > editing_DragAction = = Settings : : COPYREFERENCE ? selectedToBibTeXRefs ( ) : selectedToBibTeXText ( ) , this ) ;
T QDragObject * d = new T QTextDrag( settings - > editing_DragAction = = Settings : : COPYREFERENCE ? selectedToBibTeXRefs ( ) : selectedToBibTeXText ( ) , this ) ;
d - > dragCopy ( ) ;
}
void DocumentListView : : saveColumnIndex ( )
{
Settings * settings = Settings : : self ( m_bibtexFile ) ;
QHeader * hdr = header ( ) ;
T QHeader * hdr = header ( ) ;
for ( int i = 0 ; i < columns ( ) ; i + + )
settings - > editing_MainListColumnsIndex [ i ] = hdr - > mapToIndex ( i ) ;
@ -603,7 +603,7 @@ namespace KBibTeX
void DocumentListView : : restoreColumnIndex ( )
{
Settings * settings = Settings : : self ( m_bibtexFile ) ;
QHeader * hdr = header ( ) ;
T QHeader * hdr = header ( ) ;
for ( int i = 0 ; i < columns ( ) ; i + + )
hdr - > moveSection ( i , settings - > editing_MainListColumnsIndex [ i ] ) ;
@ -617,7 +617,7 @@ namespace KBibTeX
for ( int i = from ; i < to ; i + + )
{
if ( columnWidthMode ( i ) = = QListView: : Manual )
if ( columnWidthMode ( i ) = = T QListView: : Manual )
settings - > editing_MainListColumnsWidth [ i ] = columnWidth ( i ) ;
else
settings - > editing_MainListColumnsWidth [ i ] = 0xffff ;
@ -639,12 +639,12 @@ namespace KBibTeX
{
Settings * settings = Settings : : self ( m_bibtexFile ) ;
setSortColumn ( settings - > editing_MainListSortingColumn ) ;
setSortOrder ( settings - > editing_MainListSortingOrder > 0 ? Qt: : Ascending : Qt: : Descending ) ;
setSortOrder ( settings - > editing_MainListSortingOrder > 0 ? T Qt: : Ascending : T Qt: : Descending ) ;
}
void DocumentListView : : makeNewItemsUnread ( )
{
for ( QValueList< DocumentListViewItem * > : : ConstIterator it = m_unreadItems . begin ( ) ; it ! = m_unreadItems . end ( ) ; + + it )
for ( T QValueList< DocumentListViewItem * > : : ConstIterator it = m_unreadItems . begin ( ) ; it ! = m_unreadItems . end ( ) ; + + it )
{
( * it ) - > setUnreadStatus ( FALSE ) ;
( * it ) - > repaint ( ) ;
@ -653,36 +653,36 @@ namespace KBibTeX
m_unreadItems . clear ( ) ;
}
void DocumentListView : : slotDropped ( QDropEvent * event , QListViewItem * item )
void DocumentListView : : slotDropped ( T QDropEvent * event , T QListViewItem * item )
{
QString text ;
QStrList urlList ;
T QString text ;
T QStrList urlList ;
if ( QTextDrag: : decode ( event , text ) & & KURL ( text ) . isValid ( ) )
if ( T QTextDrag: : decode ( event , text ) & & KURL ( text ) . isValid ( ) )
urlList . append ( text ) ;
if ( ! urlList . isEmpty ( ) | | QUriDrag: : decode ( event , urlList ) )
if ( ! urlList . isEmpty ( ) | | T QUriDrag: : decode ( event , urlList ) )
{
QString url = urlList . at ( 0 ) ;
QString tmpFile ;
T QString url = urlList . at ( 0 ) ;
T QString tmpFile ;
if ( ! KIO : : NetAccess : : download ( url , tmpFile , 0 ) )
{
KMessageBox : : error ( this , KIO : : NetAccess : : lastErrorString ( ) ) ;
return ;
}
QFile f ( tmpFile ) ;
T QFile f ( tmpFile ) ;
if ( ! f . open ( IO_ReadOnly ) )
{
KMessageBox : : error ( this , f . errorString ( ) ) ;
KIO : : NetAccess : : removeTempFile ( tmpFile ) ;
return ;
}
QByteArray ba = f . readAll ( ) ;
text = QString( ba ) ;
T QByteArray ba = f . readAll ( ) ;
text = T QString( ba ) ;
f . close ( ) ;
KIO : : NetAccess : : removeTempFile ( tmpFile ) ;
}
else if ( ! QTextDrag: : decode ( event , text ) )
else if ( ! T QTextDrag: : decode ( event , text ) )
return ;
event - > accept ( TRUE ) ;
@ -691,16 +691,16 @@ namespace KBibTeX
paste ( text , dlvi ) ;
}
bool DocumentListView : : eventFilter ( QObject * watched , QEvent * e )
bool DocumentListView : : eventFilter ( T QObject * watched , T QEvent * e )
{
if ( watched = = header ( ) )
{
switch ( e - > type ( ) )
{
case QEvent: : MouseButtonPress :
case T QEvent: : MouseButtonPress :
{
if ( static_cast < QMouseEvent * > ( e ) - > button ( ) = = RightButton & & m_headerMenu ! = NULL )
m_headerMenu - > popup ( QCursor: : pos ( ) ) ;
if ( static_cast < T QMouseEvent * > ( e ) - > button ( ) = = RightButton & & m_headerMenu ! = NULL )
m_headerMenu - > popup ( T QCursor: : pos ( ) ) ;
break ;
}
@ -713,9 +713,9 @@ namespace KBibTeX
return KListView : : eventFilter ( watched , e ) ;
}
void DocumentListView : : keyPressEvent ( QKeyEvent * e )
void DocumentListView : : keyPressEvent ( T QKeyEvent * e )
{
if ( e - > key ( ) = = QKeyEvent: : Key_Enter | | e - > key ( ) = = QKeyEvent: : Key_Return )
if ( e - > key ( ) = = T QKeyEvent: : Key_Enter | | e - > key ( ) = = T QKeyEvent: : Key_Return )
{
DocumentListViewItem * item = dynamic_cast < DocumentListViewItem * > ( selectedItem ( ) ) ;
if ( item = = NULL )
@ -742,7 +742,7 @@ namespace KBibTeX
setColumnWidth ( col , colWidth ) ;
header ( ) - > setResizeEnabled ( colWidth > 0 , col ) ;
setColumnWidthMode ( col , colWidth < 0xffff ? QListView: : Manual : QListView: : Maximum ) ;
setColumnWidthMode ( col , colWidth < 0xffff ? T QListView: : Manual : T QListView: : Maximum ) ;
saveColumnWidths ( col ) ;
}
@ -759,7 +759,7 @@ namespace KBibTeX
for ( int i = 0 ; i < = ( int ) BibTeX : : EntryField : : ftYear - ( int ) BibTeX : : EntryField : : ftAbstract ; i + + )
{
BibTeX : : EntryField : : FieldType fieldType = ( BibTeX : : EntryField : : FieldType ) ( i + ( int ) BibTeX : : EntryField : : ftAbstract ) ;
QString label = Settings : : fieldTypeToI18NString ( fieldType ) ;
T QString label = Settings : : fieldTypeToI18NString ( fieldType ) ;
addColumn ( label ) ;
}
}