File indexing completed on 2024-04-14 05:35:08

0001 #!/usr/bin/perl
0002 
0003 # Laurent Montel <montel@kde.org> 2005 GPL
0004 # David Faure <faure@kde.org>
0005 # This script ports everything in the current directory (and recursively) to the Qt4 API,
0006 # for things that can be done automatically.
0007 # Note that there are many other scripts for things that require manual tweaking afterwards,
0008 # especially for things that would otherwise compile with QT3_SUPPORT so they don't need
0009 # porting initially.
0010 
0011 use File::Basename;
0012 use lib dirname( $0 );
0013 use functionUtilkde;
0014 use strict;
0015 
0016 sub addQStringElement
0017 {
0018     my $result = $_[0];
0019     if ( $result =~ /^\"/ ) {
0020     $result = "QString(" . $result . ")";
0021     }
0022     return $result;
0023 }
0024 
0025 open(my $F, "-|", qw(find . -type f));
0026 my $file;
0027 my $warning;
0028 my @files = ();
0029 while ($file = <$F>) {
0030     chomp $file;
0031     next if functionUtilkde::excludeFile( $file);
0032     my @necessaryIncludes = ();
0033 
0034     my $is_ui_file = 0;
0035     $is_ui_file = 1 if ( $file =~ /\.ui$/ );
0036 
0037     if (functionUtilkde::substInFile {
0038 
0039     if ( $_ =~ /Q3StyleSheet::escape/ ) {
0040         s!Q3StyleSheet::escape!Qt::escape!g;
0041         push(@necessaryIncludes, "QTextDocument");
0042     }
0043     if ( $_ =~ /Q3StyleSheet::convertFromPlainText/ ) {
0044         s!Q3StyleSheet::convertFromPlainText!Qt::convertFromPlainText!g;
0045         s!Q3StyleSheetItem::!Qt::!;
0046         push(@necessaryIncludes, "QTextDocument");
0047     }
0048 
0049     s!Qt::WordBreak!Qt::TextWordWrap!;
0050     s!Qt::SingleLine!Qt::TextSingleLine!;
0051     s!Qt::DontClip!Qt::TextDontClip!;
0052     s!Qt::ExpandTabs!Qt::TextExpandTabs!;
0053     s!Qt::ShowPrefix!Qt::TextShowMnemonic!;
0054     s!Qt::BreakAnywhere!Qt::TextWrapAnywhere!;
0055     s!Qt::DontPrint!Qt::TextDontPrint!;
0056     s!Qt::IncludeTrailingSpaces!Qt::TextIncludeTrailingSpaces!;
0057     s!Qt::NoAccel!Qt::TextHideMnemonic!;
0058     s!Qt::Key_BackSpace!Qt::Key_Backspace!;
0059     s!Qt::Key_BackTab!Qt::Key_Backtab!;
0060     s!Qt::Key_Prior!Qt::Key_PageUp!;
0061     s!Qt::Key_Next!Qt::Key_PageDown!;
0062     s!Qt::Key_MediaPrev([\s*|,])!Qt::Key_MediaPrevious\1!;
0063 
0064     s!Qt::arrowCursor!Qt::ArrowCursor!;
0065     s!Qt::upArrowCursor!Qt::UpArrowCursor!;
0066     s!Qt::crossCursor!Qt::CrossCursor!;
0067     s!Qt::waitCursor!Qt::WaitCursor!;
0068     s!Qt::ibeamCursor!Qt::IBeamCursor!;
0069     s!Qt::sizeVerCursor!Qt::SizeVerCursor!;
0070     s!Qt::sizeHorCursor!Qt::SizeHorCursor!;
0071     s!Qt::sizeBDiagCursor!Qt::SizeBDiagCursor!;
0072     s!Qt::sizeFDiagCursor!Qt::SizeFDiagCursor!;
0073     s!Qt::sizeAllCursor!Qt::SizeAllCursor!;
0074     s!Qt::blankCursor!Qt::BlankCursor!;
0075     s!Qt::splitVCursor!Qt::SplitVCursor!;
0076     s!Qt::splitHCursor!Qt::SplitHCursor!;
0077     s!Qt::pointingHandCursor!Qt::PointingHandCursor!;
0078     s!Qt::forbiddenCursor!Qt::ForbiddenCursor!;
0079     s!Qt::whatsThisCursor!Qt::WhatsThisCursor!;
0080     s!QScrollBar::Horizontal!Qt::Horizontal!g;
0081     s!QSlider::Horizontal!Qt::Horizontal!g; 
0082     s!QScrollBar::Vertical!Qt::Vertical!g;
0083     s!QSlider::Vertical!Qt::Vertical!g;
0084     s!QWidget::WheelFocus!Qt::WheelFocus!g;
0085 
0086     s!\bQPen::PenStyle\b!Qt::PenStyle!g;
0087     s!QSlider::Below!QSlider::TicksBelow!;
0088     s!QSlider::Above!QSlider::TicksAbove!;
0089 
0090     # Qt3 name class
0091     #s!QIconSet!QIcon!g;
0092     s!QWMatrix!QMatrix!g;
0093     s!QGuardedPtr!QPointer!g;
0094 
0095     # Qt2-compat classes :)
0096     s!QArray!Q3MemArray!g;
0097 
0098     s!IO_ReadOnly!QIODevice::ReadOnly!;
0099     s!IO_WriteOnly!QIODevice::WriteOnly!;
0100     s!IO_ReadWrite!QIODevice::ReadWrite!;
0101     s!IO_Append!QIODevice::Append!;
0102     s!IO_Truncate!QIODevice::Truncate!;
0103     s!IO_Translate!QIODevice::Text!;
0104 
0105     s!Q_INT8!qint8!g;
0106     s!Q_UINT8!quint8!g;
0107     s!Q_INT16!qint16!g;
0108     s!Q_UINT16!quint16!g;
0109     s!Q_INT32!qint32!g;
0110     s!Q_UINT32!quint32!g;
0111     s!Q_INT64!qint64!g;
0112     s!Q_UINT64!quint64!g;
0113     s!Q_LLONG!qint64!g;
0114     s!Q_ULLONG!quint64!g;
0115     s!\bQMAX\b!qMax!g;
0116     s!\bQMIN\b!qMin!g;
0117     s!\bQABS\b!qAbs!g;
0118 
0119     s!QWidget::PaletteBase!Qt::PaletteBase!;
0120     s!Qt::ShiftButton!Qt::ShiftModifier!;
0121     s!ShiftButton!Qt::ShiftModifier!;
0122     s!Qt::ControlButton!Qt::ControlModifier!;
0123     s!ControlButton!Qt::ControlModifier!;
0124     s!Qt::AltButton!Qt::AltModifier!;
0125     s!AltButton!Qt::AltModifier!;
0126     s!Qt::MetaButton!Qt::MetaModifier!;
0127     s!MetaButton!Qt::MetaModifier!;
0128     s!Qt::Keypad!Qt::KeypadModifier!;
0129     s!\bKeypad\b!Qt::KeypadModifier!;
0130     s!Qt::KeyButtonMask!Qt::KeyboardModifierMask!;
0131     s!KeyButtonMask!Qt::KeyboardModifierMask!;
0132 
0133     s!QMouseEvent::LeftButton!Qt::LeftButton!;
0134     s!QMouseEvent::RightButton!Qt::RightButton!;
0135     s!QMouseEvent::MidButton!Qt::MidButton!;
0136 
0137     s!QWidget::NoFocus!Qt::NoFocus!g;
0138 
0139     s!convertToAbs!makeAbsolute!;
0140     s!currentDirPath!currentPath!;
0141     s!homeDirPath!homePath!;
0142     s!rootDirPath!rootPath!;
0143     s!cleanDirPath!cleanPath!;
0144     s!absFilePath!absoluteFilePath!;
0145     s!QDir::SortSpec!QDir::SortFlags!;
0146     s!QDir::All!QDir::TypeMask!;
0147     s!QDir::DefaultFilter!QDir::NoFilter!;
0148     s!QDir::DefaultSort!QDir::NoSort!;
0149     s!simplifyWhiteSpace!simplified!g;
0150     s!stripWhiteSpace!trimmed!g;
0151 
0152     if ( $_ =~ /(\.ucs2|\-\>ucs2)/ ) {
0153       s!\bucs2\b!utf16!g;
0154     }
0155     s!leftJustify!leftJustified!g;
0156     s!rightJustify!rightJustified!g;
0157     s!fromUcs2!fromUtf16!g;
0158     s!constref!at!g;
0159     #s!changeInterval!start!g;
0160 
0161     s!Q3TextEdit::PlainText!Qt::PlainText!;
0162     s!\bQImage::ScaleMin\b!Qt::ScaleMin!;
0163 
0164     # When using qt3to4 with -strict (to avoid some nonsensical replacements of col.red() or enum { Top, Bottom })
0165     # we are then missing the following safer replacements:
0166     s!QWidget::WFlags!Qt::WFlags!;
0167     s!\bWFlags\b!Qt::WFlags! unless (/Qt::WFlags/);
0168     s!\bWStyle_!Qt::WStyle_!g unless (/Qt::WStyle_/);
0169     s!\bWType_!Qt::WType_!g unless (/Qt::WType_/);
0170     s!\bKey_!Qt::Key_!g unless (/Qt::Key_/);
0171     s!\bCTRL\b!Qt::CTRL!g unless (/Qt::CTRL/ || /_CTRL/ );
0172     s!\bSHIFT\b!Qt::SHIFT!g unless (/Qt::SHIFT/);
0173     s!\bLeftButton\b!Qt::LeftButton!g unless (/Qt::LeftButton/);
0174     s!\bRightButton\b!Qt::RightButton!g unless (/Qt::RightButton/);
0175     s!\bMidButton\b!Qt::MidButton!g unless (/Qt::MidButton/);
0176     s!QWidget::TabFocus!Qt::TabFocus!;
0177     s!\bTabFocus\b!Qt::TabFocus!g unless (/Qt::TabFocus/);
0178    
0179 
0180     s!QStyle::Style_Enabled!QStyle::State_Enabled!g;
0181     s!QStyle::Style_On!QStyle::State_On!g;
0182     s!QStyle::Style_Off!QStyle::State_Off!g; 
0183     s!QStyle::Style_NoChange!QStyle::State_NoChange!g;
0184 
0185     s!QWidget::StrongFocus!Qt::StrongFocus!g;
0186     s!QPushButton::StrongFocus!Qt::StrongFocus!g;
0187     s!StrongFocus!Qt::StrongFocus!g unless (/Qt::StrongFocus/ );
0188 
0189     s!QLabel::AlignLeft!Qt::AlignLeft!g;
0190     s!QLabel::AlignRight!Qt::AlignRight!g;
0191     s!QLabel::AlignCenter!Qt::AlignCenter!g;
0192     s!QLabel::AlignHCenter!Qt::AlignHCenter!g;
0193     s!QLabel::AlignVCenter!Qt::AlignVCenter!g;
0194     s!QLabel::AlignTop!Qt::AlignTop!g;
0195     s!QLabel::AlignBottom!Qt::AlignBottom!g;
0196     s!\bAlignmentFlags\b!Qt::Alignment!g unless (/Qt::Alignment/);
0197 
0198     if (!$is_ui_file) { # uic/cpp/cppwriteinitialization.cpp prepends Qt:: automatically
0199         s!\bSolidPattern\b!Qt::SolidPattern!g unless ( /Qt::SolidPattern/ );
0200         s!Dense1Pattern!Qt::Dense1Pattern!g unless ( /Qt::Dense1Pattern/ );
0201         s!Dense2Pattern!Qt::Dense2Pattern!g unless ( /Qt::Dense2Pattern/ );
0202         s!Dense3Pattern!Qt::Dense3Pattern!g unless ( /Qt::Dense3Pattern/ );
0203         s!Dense4Pattern!Qt::Dense4Pattern!g unless ( /Qt::Dense4Pattern/ );
0204         s!Dense5Pattern!Qt::Dense5Pattern!g unless ( /Qt::Dense5Pattern/ );
0205         s!Dense6Pattern!Qt::Dense6Pattern!g unless ( /Qt::Dense6Pattern/ );
0206         s!Dense7Pattern!Qt::Dense7Pattern!g unless ( /Qt::Dense7Pattern/ );
0207         s!\bHorPattern\b!Qt::HorPattern!g unless ( /Qt::HorPattern/ );
0208         s!\bVerPattern\b!Qt::VerPattern!g unless ( /Qt::VerPattern/ );
0209         s!\bCrossPattern\b!Qt::CrossPattern!g unless ( /Qt::CrossPattern/ );
0210         s!\bBDiagPattern\b!Qt::BDiagPattern!g unless ( /Qt::BDiagPattern/ );
0211         s!\bFDiagPattern\b!Qt::FDiagPattern!g unless ( /Qt::FDiagPattern/ );
0212         s!\bDiagCrossPattern\b!Qt::DiagCrossPattern!g unless ( /Qt::DiagCrossPattern/ );
0213         s!\bNoBrush\b!Qt::NoBrush!g unless (/Qt::NoBrush/);
0214     }
0215 
0216     s!\bSolidLine\b!Qt::SolidLine!g unless ( /Qt::SolidLine/ );
0217 
0218     s!QBrush::NoBrush!Qt::NoBrush!g;
0219     s!QButton::NoChange!QCheckBox::NoChange!g;
0220 
0221     s!QObject::AlignLeft!Qt::AlignLeft!g;
0222     s!QObject::AlignRight!Qt::AlignRight!g;
0223     s!QObject::AlignCenter!Qt::AlignCenter!g;
0224     s!QObject::AlignHCenter!Qt::AlignHCenter!g;
0225     s!QObject::AlignVCenter!Qt::AlignVCenter!g;
0226     s!QObject::AlignTop!Qt::AlignTop!g;
0227     s!QObject::AlignBottom!Qt::AlignBottom!g;
0228 
0229     s!Q3ListViewItem::AlignLeft!Qt::AlignLeft!g;
0230     s!Q3ListViewItem::AlignRight!Qt::AlignRight!g;
0231     s!Q3ListViewItem::AlignCenter!Qt::AlignCenter!g;
0232     s!Q3ListViewItem::AlignHCenter!Qt::AlignHCenter!g;
0233     s!Q3ListViewItem::AlignVCenter!Qt::AlignVCenter!g;
0234     s!Q3ListViewItem::AlignTop!Qt::AlignTop!g;
0235     s!Q3ListViewItem::AlignBottom!Qt::AlignBottom!g;
0236 
0237 
0238     s!AlignLeft!Qt::AlignLeft!g unless (/Qt::AlignLeft/ || /"Align/ || /AlignLeft\(.*\)/);
0239     s!AlignRight!Qt::AlignRight!g unless (/Qt::AlignRight/ || /"Align/ || /AlignRight\(.*\)/);
0240     s!AlignCenter!Qt::AlignCenter!g unless (/Qt::AlignCenter/ || /"Align/ || /AlignCenter\(.*\)/);
0241     s!AlignHCenter!Qt::AlignHCenter!g unless (/Qt::AlignHCenter/ || /"Align/ || /AlignHCenter\(.*\)/);
0242     s!AlignVCenter!Qt::AlignVCenter!g unless (/Qt::AlignVCenter/ || /"Align/ || /AlignVCenter\(.*\)/);
0243     s!AlignTop!Qt::AlignTop!g unless (/Qt::AlignTop/ || /"Align/ || /AlignTop\(.*\)/);
0244     s!AlignBottom!Qt::AlignBottom!g unless (/Qt::AlignBottom/ || /"Align/ || /AlignBottom\(.*\)/);
0245     
0246     s!QCursor::WaitCursor!Qt::waitCursor!g;
0247     s!QSplitter::Vertical!Qt::Vertical!g;
0248     s!QSplitter::Horizontal!Qt::Horizontal!g;
0249 
0250     s!\bQSqlError::Connection\b!QSqlError::ConnectionError!g;
0251     s!QSqlError::None!QSqlError::NoError!g;
0252     s!\bQSqlError::Statement\b!QSqlError::StatementError!g;
0253     s!\bQSqlError::Transaction\b!QSqlError::TransactionError!g;
0254     s!\bQSqlError::Unknown\b!QSqlError::UnknownError!g;
0255 
0256 
0257     if (/app/i) {
0258     s!flushX!flush!; # QApplication
0259     }
0260     s!qt_xdisplay\s*\(\s*\)!QX11Info::display()!;
0261     s!qt_xrootwin\s*\(\s*\)!QX11Info::appRootWindow()!;
0262     s!qt_x_time!QX11Info::appTime()!;
0263     if (/QX11Info/) {
0264         push(@necessaryIncludes, "QX11Info");
0265     }
0266     if (/qHeapSort/) {
0267     push(@necessaryIncludes, "q3tl.h");
0268     }
0269 
0270     s!class QWidgetList;!typedef QList<QWidget *> QWidgetList;!;
0271 
0272     # this changes usage of QObjectList, since queryList returns QObjectList and not a pointer in qt4.
0273     s!QObjectList\s*\*!QObjectList ! if (/queryList/);
0274 
0275     } $file) { push(@files,$file); }
0276 
0277     my %alreadyadded = {};
0278     foreach my $inc (@necessaryIncludes) {
0279         next if (defined $alreadyadded{$inc});
0280         $alreadyadded{$inc} = 1;
0281         functionUtilkde::addIncludeInFile( $file, $inc );
0282     }
0283 }
0284 functionUtilkde::diffFile( @files );
0285 warn "Warning: $warning\n" if ($warning != "");